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:
When executed
curl -I http://www.a.com/img
curl -I http://www.a.com/imge 匹配到^~ /img
curl -I http://www.a.com/imges 匹配到 ~ /img
curl -I http://www.a.com/imgesssss 匹配到 ~ /img
Change the position of ~*
curl -I http://www.a.com/imge 匹配~* /img
curl -I http://www.a.com/imagessss 匹配~* /img