nginx 重定向 url参数问题

`

upstream leizi { 
#machine0
    server 10.128.25.28:8090 weight=1;
#machine1
    server 10.128.27.239:8090 weight=1;
}`


`

    listen       5000;
    server_name  10.128.27.239;
     location /jysms/machine0 {
        proxy_pass  http://10.128.25.28:8090; #请求转向machine0的服务器列表
        proxy_redirect  default; 
        proxy_set_header Host $http_host;
        proxy_set_header RBody $request_body;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
    location /jysms/machine1 {
        proxy_pass  http://10.128.27.239:8090; #请求转向machine1的服务器列表
        proxy_redirect  default; 
        proxy_set_header Host $http_host;
        proxy_set_header RBody $request_body;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
    location /jysms/ {
        proxy_pass  http://leizi; #请求转向leizi定义的服务器列表
        proxy_redirect  default; 
        proxy_set_header Host $http_host;
        proxy_set_header RBody $request_body;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }`
    
    
    

我想jysms的随意转发到10.128.27.239或者10.128.25.28
/jysms/machine0固定转发到10.128.25.28
/jysms/machine1固定转发到10.128.27.239

但是这样写之后machine0还是会转发到10.128.27.239。
请问怎么写/jysms/下剔除/jysms/machine0和/jysms/machine1转发到http://leizi;

阅读 2.5k
1 个回答

server {

    listen       5000;
    server_name  10.128.27.239;

    location /jysms/ {
    location /jysms/machine0 {
        proxy_pass  http://10.128.25.28:8090; #请求转向machine0的服务器列表
        proxy_redirect  default; 
        proxy_set_header Host $http_host;
        proxy_set_header RBody $request_body;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
    location /jysms/machine1 {
        proxy_pass  http://10.128.27.239:8090; #请求转向machine1的服务器列表
        proxy_redirect  default; 
        proxy_set_header Host $http_host;
        proxy_set_header RBody $request_body;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
        proxy_pass  http://leizi; #请求转向leizi定义的服务器列表
        proxy_redirect  default; 
        proxy_connect_timeout 5;
        proxy_set_header Host $http_host;
        proxy_set_header RBody $request_body;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    location / {
        root  C:\src\BTJYDM\jysmsWeb\dist;
        index index.html index.htm;
    }
            
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏