nginx配置之proxy_pass路径加斜杠/以及包含路径的区别
nginx配置看似简单,但一些细节配置经常被大家忽略。
在proxy_pass中
1.proxy_pass包含路径如 http://127.0.0.1:8080/abc 和http://127.0.0.1:8080规则都有区别。
2.proxy_pass结尾加斜杠/和不加斜杠的有区别
下面四种情况分别用http://192.168.10.1/proxy/test.html 进行访问。
第一种(末尾加斜杠,proxy_pass中不包含路径):
location /proxy/ { proxy_pass http://127.0.0.1:81/; }
结论:会被代理到http://127.0.0.1:81/test.html (proxy_pass+请求url匹配的location路径后的内容)
第二种(末尾不加斜杠,proxy_pass不包含路径)
location /proxy/ { proxy_pass http://127.0.0.1:81; }
结论:会被代理到http://127.0.0.1:81/proxy/test.html (proxy_pass替换请求url的ip和端口)
第三种(末尾加斜杠,proxy_pass包含路径):
location /proxy/ { proxy_pass http://127.0.0.1:81/abc/; }
结论:会被代理到http://127.0.0.1:81/abc/test.html (proxy_pass+请求url匹配的location路径后的内容)
第四种(末尾不加斜杠,url包含路径):
location /proxy/ { proxy_pass http://127.0.0.1:81/abc; }
结论:会被代理到http://127.0.0.1:81/abctest.html (proxy_pass+请求url匹配的location路径后的内容)
总结:
2.proxy_pass后面没有斜杠,
a.只有当proxy_pass只有IP加端口,无路径时。匹配规则为proxy_pass替换原请求url的ip和端口, 同时保留了location路径。例子为上述的第二种情况。 b.当proxy_pass端口后包含路径时,匹配规则同1.
3.推荐:一般建议proxy_pass后面不包含路径 通过查看tomcat或者接受请求的服务器方日志,我们可以看到每次请求的后端的uri完整的值,进行核对
下一篇:
SSRF(服务器请求伪造)