Skip to content

Instantly share code, notes, and snippets.

@jugyo
Created September 27, 2012 09:02
Show Gist options
  • Save jugyo/3793003 to your computer and use it in GitHub Desktop.
Save jugyo/3793003 to your computer and use it in GitHub Desktop.
nginx.conf to switch proxy for mobile
http {
upstream app-pc {
server 127.0.0.1:8001;
}
upstream app-mobile {
server 127.0.0.1:8002;
}
server {
listen 8080;
server_name localhost;
# check user agent
if ($http_user_agent ~* '(iPhone|iPod|Opera Mini|Android.*Mobile|NetFront|PSP|BlackBerry|Windows Phone)') {
set $ua_type "@mobile";
}
location / {
# root
if ($ua_type = "@mobile"){
set $page_cache_path /var/www/app_pc/public;
}
if ($ua_type != "@mobile"){
set $page_cache_path /var/www/app_mobile/public;
}
root $page_cache_path;
# for page cache
if (-f $request_filename) {
break;
}
if (-f $request_filename/index.html) {
rewrite (.*) $1/index.html break;
}
if (-f $request_filename.html) {
rewrite (.*) $1.html break;
}
# proxy
if ($ua_type = "@mobile"){
proxy_pass http://app-mobile;
}
if ($ua_type != "@mobile"){
proxy_pass http://app-pc;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment