nginx proxy_pass后的url加不加/的区别

           在nginx中配置proxy_pass时,当在后面的url加上了/,相当于是绝对根路径,则nginx不会把location中匹配的路径部分代理走;如果没有/,则会把匹配的路径部分也给代理走。

测试文件为test.html ,访问 http://127.0.0.1/proxy/ test.html 下面两种情况分别转发到不同地址,效果也各不相同。

第一种:

location  /proxy/ {
          proxy_pass http://192.168.0.100/;
}

nginx匹配到  /proxy/ 后后面的会被代理到http://192.168.0.100/test.html 这个url

第二咱(相对于第一种,最后少一个 /)

location  /proxy/ {
          proxy_pass http://192.168.0.100;
}

nginx匹配到  /proxy/ 后后面的会被代理到http://192.168.0.100/proxy/test.html 这个url

发表评论

您的邮箱地址不会被公开。