proxy_pass配置中url末尾帶/時,nginx轉(zhuǎn)發(fā)時,會將原uri去除location匹配表達(dá)式后的內(nèi)容拼接在proxy_pass中url之后。
測試地址:http://192.168.171.129/test/test.jsp
場景一:
location ^~ /test/ {
proxy_pass http://192.168.171.129:8080/server/;
}
代理后實(shí)際訪問地址:http://192.168.171.129:8080/server/test.jsp
場景二:
location ^~ /test {
proxy_pass http://192.168.171.129:8080/server/;
}
代理后實(shí)際訪問地址:http://192.168.171.129:8080/server//test.jsp
場景三:
location ^~ /test/ {
proxy_pass http://192.168.171.129:8080/;
}
代理后實(shí)際訪問地址:http://192.168.171.129:8080/test.jsp
場景四:
location ^~ /test {
proxy_pass http://192.168.171.129:8080/;
}
代理后實(shí)際訪問地址:http://192.168.171.129:8080//test.jsp
proxy_pass配置中url末尾不帶/時,如url中不包含path,則直接將原uri拼接在proxy_pass中url之后;如url中包含path,則將原uri去除location匹配表達(dá)式后的內(nèi)容拼接在proxy_pass中的url之后。
測試地址:http://192.168.171.129/test/tes.jsp
場景一:
location ^~ /test/{
proxy_pass http://192.168.171.129:8080/server;
}
代理后實(shí)際訪問地址:http://192.168.171.129:8080/servertes.jsp
場景二:
location ^~ /test {
proxy_pass http://192.168.171.129:8080/server;
}
代理后實(shí)際訪問地址:http://192.168.171.129:8080/server/tes.jsp
場景三:
location ^~ /test/ {
proxy_pass http://192.168.171.129:8080;
}
代理后實(shí)際訪問地址:http://192.168.171.129:8080/test/tes.jsp
場景四:
location ^~ /test {
proxy_pass http://192.168.171.129:8080;
}
代理后實(shí)際訪問地址:http://192.168.171.129:8080/test/tes.jsp