1. 首页
  2. 技术知识

nginx配置proxy_pass中url末尾带/与不带/的区别详解

nginx配置proxy_pass时url末尾带“/”与不带“/”的区别如下:

注意:当location为正则表达式匹配模式时,proxy_pass中的url末尾是不允许有”/”的,因此正则表达式匹配模式不在讨论范围内。

proxy_pass配置中url末尾带/时,nginx转发时,会将原uri去除location匹配表达式后的内容拼接在proxy_pass中url之后。

测试地址:http://192.168.171.129/test/tes.jsp

场景一:

location ^~ /test/ {

proxy_pass http://192.168.171.129:8080/server/;

}

X后实际访问地址:http://192.168.171.129:8080/server/tes.jsp

场景二:

location ^~ /test {

proxy_pass http://192.168.171.129:8080/server/;

}

X后实际访问地址:http://192.168.171.129:8080/server//tes.jsp

场景三:

location ^~ /test/ {

proxy_pass http://192.168.171.129:8080/;

}X后实际访问地址:http://192.168.171.129:8080/tes.jsp

场景四:

location ^~ /test {

proxy_pass http://192.168.171.129:8080/;

}

X后实际访问地址:http://192.168.171.129:8080//tes.jsp


proxy_pass配置中url末尾不带/时,如url中不包含path,则直接将原uri拼接在proxy_pass中url之后;如url中包含path,则将原uri去除location匹配表达式后的内容拼接在proxy_pass中的url之后。


测试地址:http://192.168.171.129/test/tes.jsp

场景一:

location ^~ /test/{

proxy_pass http://192.168.171.129:8080/server;

}X后实际访问地址:http://192.168.171.129:8080/servertes.jsp

场景二:

location ^~ /test {

proxy_pass http://192.168.171.129:8080/server;

}

X后实际访问地址:http://192.168.171.129:8080/server/tes.jsp

场景三:

location ^~ /test/ {

proxy_pass http://192.168.171.129:8080;

}X后实际访问地址:http://192.168.171.129:8080/test/tes.jsp

场景四:

location ^~ /test {

proxy_pass http://192.168.171.129:8080;

}X后实际访问地址:http://192.168.171.129:8080/test/tes.jsp

到此这篇关于nginx配置proxy_pass中url末尾带/与不带/的区别详解的文章就介绍到这了,更多相关nginx proxy_pass url末尾内容请搜索共生网络以前的文章或继续浏览下面的相关文章希望大家以后多多支持共生网络!

原创文章,作者:starterknow,如若转载,请注明出处:https://www.starterknow.com/107818.html

联系我们