nginx proxy_pass参数配置带不带‘/’

1. proxy_pass 配置的url后面,不加'/',那么重定向后,追加location后的路径。
比如server_name: 10.9.11.225
location /proxy1/{
proxy_pass http://10.9.11.166:8540/;
}
location  /proxy2/ {
          proxy_pass http://10.9.11.166:8540/haha/;
}
如果访问 10.9.11.225/proxy1/   会代理到http://10.9.11.166:8540/
如果访问 10.9.11.225/proxy2/   会代理到http://10.9.11.166:8540/haha/

2. 如果proxy_pass配置的url后面,不加'/',那么重定向后,整个替换location后的路径。
location /proxy3/{
proxy_pass http://10.9.11.166:8540;
}
location  /proxy4/ {
          proxy_pass http://10.9.11.166:8540/haha;
}
访问http://10.9.11.225/proxy/就会被反向代理到http://10.9.11.166:8540/proxy/
访问http://10.9.11.225/proxy4/index.html就会被反向代理到http://10.9.11.166:8540/hahaindex.html

猜你喜欢

转载自www.cnblogs.com/lixiaoxuan/p/10918564.html