nginx反向代理proxy_pass url后加"/"与不加"/"的区别

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

例:访问路径为 /pss/bill.html

当nginx配置文件proxy_pass后边的url带"/"时,代理到后端的路径为:http://127.0.0.1:18081/bill.html,省略了匹配到的/pss/路径;

location /pss/ {
proxy_pass http://127.0.0.1:18081/;
}

当nginx配置文件proxy_pass后边的url不带"/"时,代理到后端的路径为:http://127.0.0.1:18081/pss/bill.html,连同匹配到的/pss/路径,一起进行反向代理;

location /pss/ {
proxy_pass http://127.0.0.1:18081;
}

posted @ 2019-12-31 16:49  程牧  阅读(1216)  评论(0编辑  收藏  举报