nginx reverse proxy cofinguration
basedonourcase,weneedtohandletwodifferenturlrequest:
example/0.5/xxx==>192.168.1.100:8080/xxx
example/0.7/xxx==>192.168.1.101:8080/xxx
Hereistheconfiguration:
root@p1:/etc/nginx/conf.d#cat/etc/nginx/conf.d/default.conf
##Basicreverseproxyserver##
##Apache(vm02)backendforwww.example.com##
upstreamdevelopserver{
server192.168.1.100:8080;#DevelopServer
}
##Lighttpd(vm01)backendforstatic.example.com##
upstreamproductionserver{
server192.168.1.100:8080;#ProductionServer
}
##Startwww.example.com##
server{
listen10.0.3.138:80;#ipaddressofproxyserver
server_namewww.example.com;
access_log/var/log/nginx/www.example.access.logmain;
error_log/var/log/nginx/www.example.error.log;
root/usr/share/nginx/html;
indexindex.htmlindex.htm;
##sendrequestbacktoapache1##
location/0.5{
rewrite/0\.5/(.*)/$1break;
proxy_passhttp://developserver;
proxy_next_upstreamerrortimeoutinvalid_headerhttp_500http_502http_503http_504;
proxy_redirectoff;
proxy_bufferingoff;
proxy_set_headerHost$host;
proxy_set_headerX-Real-IP$remote_addr;
proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;
}
location/0.7{
proxy_passhttp://productionserver;
rewrite/0\.7/(.*)/$1break;
proxy_next_upstreamerrortimeoutinvalid_headerhttp_500http_502http_503http_504;
proxy_redirectoff;
proxy_bufferingoff;
proxy_set_headerHoststatic.example.com;
proxy_set_headerX-Real-IP$remote_addr;
proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;
}
}
root@p1:/etc/nginx/conf.d#diff-u/etc/nginx/nginx.conf.bkp/etc/nginx/nginx.conf
---/etc/nginx/nginx.conf.bkp2015-08-2814:09:19.744354204+0800
+++/etc/nginx/nginx.conf2015-08-2814:55:35.264441341+0800
@@-22,7+22,9@@
#server_names_hash_bucket_size64;
#server_name_in_redirectoff;
-
+log_formatmain'$remote_addr-$remote_user[$time_local]$request'
+'"$status"$body_bytes_sent"$http_referer"'
+'"$http_user_agent""$http_x_forwarded_for""$gzip_ratio"';
include/etc/nginx/mime.types;
default_typeapplication/octet-stream;