nginx中proxy

您所在的位置:网站首页 nginx中proxy_pass nginx中proxy

nginx中proxy

2023-03-28 13:22| 来源: 网络整理| 查看: 265

nginx配置中"/“字符苦恼很多小伙伴,看完这一篇吃透”/"。 加不加"/",区别真的那么大吗?我们带着这个疑问,来探究下这个问题。 location目录匹配详解: nginx每个location都是一个匹配目录,nginx的策略是:访问请求来时,会对访问地址进行解析,从上到下逐个匹配,匹配上就执行对应location大括号中的策略,并根据策略对请求作出相应。 1、第一种:加"/"

location /test/ { proxy_pass http://localhost:8181/; }

测试结果,请求被代理到:http://localhost:8181/index.html

2、第二种:不加"/"

location /test/ { proxy_pass http://localhost:8181; }

测试结果,请求被代理到:http://localhost:8181/test/index.html

3、第三种:增加目录"/"

location /test/ { proxy_pass http://localhost:8181/static/; }

测试结果,请求被代理到:http://localhost:8181/static/index.html

4、第四种:增加目录不加"/"

location /test/ { proxy_pass http://localhost:8181/static; }

测试结果,请求被代理到:http://localhost:8181/staticindex.html

总结: location目录后加"/",只能匹配目录,不加“/”不仅可以匹配目录还对目录进行模糊匹配。而proxy_pass无论加不加“/”,代理跳转地址都直接拼接。



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3