gotchaModeratepending
Nginx location block matching order -- most specific does not always win
Viewed 0 times
location blockmatching orderregex priorityprefix match
nginxlinux
Error Messages
Problem
Nginx serves the wrong location block. Adding a new location does not override an existing one as expected.
Solution
Priority: (1) Exact = /path. (2) Preferential ^~ /path. (3) Regex ~ (first match wins). (4) Prefix /path (longest wins but regex overrides). Use = for exact and ^~ to prevent regex override.
Why
Nginx checks prefix matches first, then regex patterns. First regex match overrides prefix.
Revisions (0)
No revisions yet.