Learn nginx-location priority

nginx-location matching priority

Exact match (case sensitive)
location = /img { }The starting character matches ^~ will detect all matches, (case sensitive) location ^~ /img { } Regular matching location ~ /imge{ ( case sensitive) Write) } location ~* /img {(not case sensitive) } Ordinary starting string matching location /imges {: (case sensitive) }
















Exact matching has the highest priority, when: initial matching string length <= uri length <normal initial string matching length, initial matching string length priority
When uri length >= ordinary initial string matching length, regular matching priority
does not exist ordinary When the starting string is matched, the starting string is matched first. The
two regular matches do not have priority. Whoever writes in the front of the configuration file has priority .
The sample configuration file is shown in the figure:
Insert picture description here

When executed

curl -I http://www.a.com/img

Insert picture description here

curl -I http://www.a.com/imge   匹配到^~ /img

Insert picture description here

curl  -I  http://www.a.com/imges    匹配到 ~ /img

Insert picture description here

curl  -I  http://www.a.com/imgesssss  匹配到 ~ /img

Insert picture description here

Change the position of ~*

Insert picture description here

curl -I http://www.a.com/imge  匹配~* /img

Insert picture description here

curl -I http://www.a.com/imagessss  匹配~* /img 

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_45937255/article/details/115305453