Nginx访问路径A分配到A服务器,访问路径B分配到B服务器,不指定随机分配

upstream test.cc {
    server 192.168.197.105:81;
    server 192.168.197.105:82;
}
upstream test1.cc {
    server 192.168.197.105:81;
}
upstream test2.cc {
    server 192.168.197.105:82;
}

server {
    listen 80;
    server_name 192.168.197.105;
    access_log  /var/log/nginx/access.log  access_json;
    location /test1.html {
        proxy_pass http://test1.cc;
        proxy_set_header Host $host:$server_port;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Real-PORT $remote_port;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
    location /test2.html {
        proxy_pass http://test2.cc;
        proxy_set_header Host $host:$server_port;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Real-PORT $remote_port;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
    location / {
        proxy_pass http://test.cc;
        proxy_set_header Host $host:$server_port;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Real-PORT $remote_port;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

 

1、访问http://192.168.197.105

 

 

2、访问http://192.168.197.105/test1.html

 

 

3、访问http://192.168.197.105/test2.html

 

 

posted @ 2020-08-06 20:00  Frank-hui  阅读(742)  评论(0编辑  收藏  举报