关键代码如下:
http {
upstream php_server {
server 192.168.1.10:8080;
}
upstream java_server {
server 192.168.1.10:8081;
}
upstream asp_server {
server 192.168.1.20:8082;
}
server {
listen 80;
server_name localhost;
location ^~ /java/ {
proxy_pass http://java_server/;
proxy_set_header host $host;
proxy_set_header X-forwarded-for $proxy_add_x_forwarded_for;
proxy_set_header X-real-ip $remote_addr;
}
location ^~ /asp/ {
proxy_pass http://asp_server/;
proxy_set_header host $host;
proxy_set_header X-forwarded-for $proxy_add_x_forwarded_for;
proxy_set_header X-real-ip $remote_addr;
}
location / {
proxy_pass http://php_server;
proxy_set_header host $host;
proxy_set_header X-forwarded-for $proxy_add_x_forwarded_for;
proxy_set_header X-real-ip $remote_addr;
}
}