How do location block matching priorities work in NGINX?
⚡
Quick Answer
Exact (=) wins, then longest prefix with ^~ (stops regex), then regex (~/~*) in order, then plain longest prefix.
Detailed Answer
NGINX picks the most specific match: = exact match first; ^~ prefix suppresses regex checks; regex matches are tried in file order; otherwise the longest matching prefix location is used. Misordered locations are a top source of 'wrong handler' bugs.
💡
Interview Tip
Know the precedence order — a classic gotcha.
nginxlocationmatching