What order do location directives fire in?
This question is related to
nginx
It fires in this order.
=
(exactly)
location = /path
^~
(forward match)
location ^~ /path
~
(regular expression case sensitive)
location ~ /path/
~*
(regular expression case insensitive)
location ~* .(jpg|png|bmp)
/
location /path
Locations are evaluated in this order:
location = /path/file.ext {}
Exact matchlocation ^~ /path/ {}
Priority prefix match -> longest firstlocation ~ /Paths?/ {}
(case-sensitive regexp) and location ~* /paths?/ {}
(case-insensitive regexp) -> first matchlocation /path/ {}
Prefix match -> longest firstThe priority prefix match (number 2) is exactly as the common prefix match (number 4), but has priority over any regexp.
For both prefix matche types the longest match wins.
Case-sensitive and case-insensitive have the same priority. Evaluation stops at the first matching rule.
Documentation says that all prefix rules are evaluated before any regexp, but if one regexp matches then no standard prefix rule is used. That's a little bit confusing and does not change anything for the priority order reported above.
There is a handy online tool for testing location priority now:
location priority testing online
Source: Stackoverflow.com