proxy_pass配置中url末尾带/时,
nginx转发时,会将原uri去除location匹配表达式后的内容拼接在proxy_pass中url之后。
测试地址:http://192.168.171.129/aaa/bbb.jsp
场景一:
location ^~ /aaa/ {
proxy_pass http://192.168.171.129:8080/server/;
}
代理后实际访问地址:http://192.168.171.129:8080/server/bbb.jsp
场景二:
location ^~ /aaa {
proxy_pass http://192.168.171.129:8080/server/;
}
代理后实际访问地址:http://192.168.171.129:8080/server//bbb.jsp
场景三:
location ^~ /aaa/ {
proxy_pass http://192.168.171.129:8080/;
}
代理后实际访问地址:http://192.168.171.129:8080/bbb.jsp
场景四:
location ^~ /aaa {
proxy_pass http://192.168.171.129:8080/;
}
代理后实际访问地址:http://192.168.171.129:8080//bbb.jsp
proxy_pass配置中url末尾不带/时,
如url中包含path,则将原uri去除location匹配表达式后的内容拼接在proxy_pass中的url之后
如url中不包含path,则直接将原uri拼接在proxy_pass中url之后;
测试地址:http://192.168.171.129/aaa/bbb.jsp
场景一:
location ^~ /aaa/{
proxy_pass http://192.168.171.129:8080/server;
}
代理后实际访问地址:http://192.168.171.129:8080/serverbbb.jsp
场景二:
location ^~ /aaa {
proxy_pass http://192.168.171.129:8080/server;
}
代理后实际访问地址:http://192.168.171.129:8080/server/bbb.jsp
----------------全转发-----------------------------------------------------------------------------
场景三:
location ^~ /aaa/ {
proxy_pass http://192.168.171.129:8080;
}
代理后实际访问地址:http://192.168.171.129:8080/aaa/bbb.jsp
场景四:
location ^~ /aaa {
proxy_pass http://192.168.171.129:8080;
}
代理后实际访问地址:http://192.168.171.129:8080/aaa/bbb.jsp
网友评论