based on our case, we need to handle two different url request:
example/0.5/xxx ==> 192.168.1.100:8080/xxx
example/0.7/xxx ==> 192.168.1.101:8080/xxx
Here is the configuration:
[quote]
[color=blue]root@p1:/etc/nginx/conf.d# cat /etc/nginx/conf.d/default.conf [/color]
## Basic reverse proxy server ##
## Apache (vm02) backend for www.example.com ##
upstream developserver {
server 192.168.1.100:8080; #Develop Server
}
## Lighttpd (vm01) backend for static.example.com ##
upstream productionserver {
server 192.168.1.100:8080; #Production Server
}
## Start www.example.com ##
server {
[color=blue] listen 10.0.3.138:80; # ip address of proxy server[/color]
server_name www.example.com;
access_log /var/log/nginx/www.example.access.log main;
error_log /var/log/nginx/www.example.error.log;
root /usr/share/nginx/html;
index index.html index.htm;
## send request back to apache1 ##
location /0.5 {
[color=red] rewrite /0\.5/(.*) /$1 break;[/color]
proxy_pass http://developserver;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_redirect off;
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /0.7 {
proxy_pass http://productionserver;
[color=red] rewrite /0\.7/(.*) /$1 break;[/color]
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_redirect off;
proxy_buffering off;
proxy_set_header Host static.example.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
[/quote]
[quote]
[color=blue]root@p1:/etc/nginx/conf.d# diff -u /etc/nginx/nginx.conf.bkp /etc/nginx/nginx.conf[/color]
--- /etc/nginx/nginx.conf.bkp 2015-08-28 14:09:19.744354204 +0800
+++ /etc/nginx/nginx.conf 2015-08-28 14:55:35.264441341 +0800
@@ -22,7 +22,9 @@
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
-
+ log_format main '$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_type application/octet-stream;
[/quote]
example/0.5/xxx ==> 192.168.1.100:8080/xxx
example/0.7/xxx ==> 192.168.1.101:8080/xxx
Here is the configuration:
[quote]
[color=blue]root@p1:/etc/nginx/conf.d# cat /etc/nginx/conf.d/default.conf [/color]
## Basic reverse proxy server ##
## Apache (vm02) backend for www.example.com ##
upstream developserver {
server 192.168.1.100:8080; #Develop Server
}
## Lighttpd (vm01) backend for static.example.com ##
upstream productionserver {
server 192.168.1.100:8080; #Production Server
}
## Start www.example.com ##
server {
[color=blue] listen 10.0.3.138:80; # ip address of proxy server[/color]
server_name www.example.com;
access_log /var/log/nginx/www.example.access.log main;
error_log /var/log/nginx/www.example.error.log;
root /usr/share/nginx/html;
index index.html index.htm;
## send request back to apache1 ##
location /0.5 {
[color=red] rewrite /0\.5/(.*) /$1 break;[/color]
proxy_pass http://developserver;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_redirect off;
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /0.7 {
proxy_pass http://productionserver;
[color=red] rewrite /0\.7/(.*) /$1 break;[/color]
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_redirect off;
proxy_buffering off;
proxy_set_header Host static.example.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
[/quote]
[quote]
[color=blue]root@p1:/etc/nginx/conf.d# diff -u /etc/nginx/nginx.conf.bkp /etc/nginx/nginx.conf[/color]
--- /etc/nginx/nginx.conf.bkp 2015-08-28 14:09:19.744354204 +0800
+++ /etc/nginx/nginx.conf 2015-08-28 14:55:35.264441341 +0800
@@ -22,7 +22,9 @@
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
-
+ log_format main '$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_type application/octet-stream;
[/quote]