在nginx配置文件中进行代理转发时,如果在proxy_pass后面的url加/,代表绝对路径,替换被代理路径;如果不加,代表相对路径,将匹配到的url路径追加到代理路径;
eg:
所有实例都调用请求http://www.test.com/test/aaa.html
第一种:
location /test/ {
proxy_pass http://127.0.0.1:8080
}
结论:http://www.test.com/test/aaa.html 代理为 http://127.0.0.1:8080/test/aaa.html
第二种:相比第一种代理服务多了/
location /test/ {
proxy_pass http://127.0.0.1:8080/
}
结论:http://www.test.com/test/aaa.html 代理为 http://127.0.0.1:8080/aaa.html
第三种:相比第二种代理服务多了/demo
location /test/ {
proxy_pass http://127.0.0.1:8080/demo
}
结论:http://www.test.com/test/aaa.html 代理为 http://127.0.0.1:8080/demoaaa.html
第四种:相比第三种代理服务多了最后一个/
location /test/ {
proxy_pass http://127.0.0.1:8080/demo/
}
结论:http://www.test.com/test/aaa.html 代理为 http://127.0.0.1:8080/demo/aaa.html