nginx中的location匹配规则

nginx代理需要注意的点:

  1、如果location里面有正则表达式,那么proxy_pass后面只能是http://ip:port这种模式,不能是http://ip:port+path这种路径

  2、location的路径最好以斜杠结尾

  3、proxy_pass如果是http://ip:port+path这种模式,那么最好以斜杠结尾

nginx proxy_pass的原则:

  1、如果proxy_pass是http://ip:port这种模式,那么如果下游请求的uri是多少,下游请求的uri就是多少,和location无关。这种情况可以配置location的正则

  2、如果proxy_pass是http://ip:port+path这种模式,那么如果下游请求的uri是多少,下游请求的uri就是http://ip:port+path+(uri减去location路径),与location有关。这种情况不能配置location的正则。

nginx的root规则:

  真实路径等于:root路径+uri,与location无关。

nginx匹配的优先级:

1、location = /img/ {}精确匹配

2、location ^~ /img/ {}前缀匹配,最长匹配规则与书写顺序无关,路径中不能有正则。

3、location ~ /img/ {}或者location ~* /img/ {}正则匹配:按照书写的顺序决定匹配的先后顺序

4、location /img/ {}不带任何修饰符的前缀匹配,最长匹配规则和书写顺序无关

5、location / {}默认匹配,会匹配所有的请求,但是在最后才能匹配到,优先级最低

参考文献:

nginx location匹配规则:https://blog.csdn.net/tzy233/article/details/79780444

nginx proxy_pass路径规则:https://blog.csdn.net/u010786902/article/details/91414747

nginx proxy_pass路径规则2:https://blog.csdn.net/lovelife2016/article/details/89885903

nginx的缓冲配置:https://blog.csdn.net/weixin_30795127/article/details/97385091

posted @ 2019-05-14 10:00  海平面下的我们  阅读(475)  评论(0编辑  收藏  举报