总结: proxy_pass如果仅是域名或者域名+端口,后面不跟“/”和其他路径,则代理后的路径为proxy_pass + location/xx。
如果proxy_pass后面带有“/” 和 其他路径,则代理后的路径为 proxy_pass + /xx(不带匹配的location);
例子1
location /web{
proxy_pass http://127.0.0.1:8080;
}
访问地址
http://127.0.0.1:8080/web/abc
代理后
http://127.0.0.1:8080/web/abc
例子2
location /web{
proxy_pass http://127.0.0.1:8080/;
}
访问地址
http://127.0.0.1:8080/web/abc
代理后
http://127.0.0.1:8080/abc
访问地址
http://127.0.0.1:8080/web?abc=123
代理后
http://127.0.0.1:8080/?abc=123
例子3
location /web{
proxy_pass http://127.0.0.1:8080/other;
}
访问地址
http://127.0.0.1:8080/web/abc
代理后
http://127.0.0.1:8080/other/abc
访问地址
http://127.0.0.1:8080/web?abc=123
代理后
http://127.0.0.1:8080/other?abc=123
例子4
location /web/{
proxy_pass http://127.0.0.1:8080/other/;
}
访问地址
http://127.0.0.1:8080/web/abc
代理后
http://127.0.0.1:8080/other/abc