Nginx Location Match Tester
Paste your location blocks and a list of request paths to see which location Nginx chooses for each one, and why.
Free · No sign-up · Your inputs stay in your browser
Input
Test which Nginx location block matches a URL
Output
7 locations, 8 paths
| Path | Location | Why |
|---|---|---|
| / | location = / | exact match, search stops |
| /about | location / | longest prefix, no regex matched |
| /static/logo.png | location ^~ /static/ | longest prefix is ^~, regexes skipped |
| /uploads/logo.PNG | location ~* \.(png|jpe?g|webp|svg)$ | first matching regex (line 5), beats prefix / |
| /api/users | location /api/ | longest prefix, no regex matched |
| /index.php | location ~ \.php$ | first matching regex (line 6), beats prefix / |
| /.env | location ~ /\.(?!well-known) | first matching regex (line 7), beats prefix / |
| /.well-known/acme-challenge/x | location / | longest prefix, no regex matched |
Nginx's order: an exact = match wins outright; otherwise it remembers the longest matching prefix, and if that prefix has ^~ it stops; otherwise regex locations are tried in the order they appear and the first match wins; only if none matches is the remembered prefix used. Order of prefix locations never matters, order of regexes always does.
Runs in this browser. Nothing you paste is sent to a server.
About this tool
Method, assumptions, practical next steps, and limits.
Order matters only for regexes
Prefix locations are compared by length, so their order in the file never matters. Regex locations are tried top to bottom, so a broad regex above a specific one shadows it. That asymmetry, documented in the location directive reference, is behind most "why does this location not apply" questions.
^~ for static paths
Marking a static prefix such as /static/ or /assets/ with ^~ stops Nginx from also testing the regexes, so a request for /static/app.php is served as a file rather than handed to the PHP location.