Skip to content
gohacks.dev
DevOps

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

PathLocationWhy
/location = /exact match, search stops
/aboutlocation /longest prefix, no regex matched
/static/logo.pnglocation ^~ /static/longest prefix is ^~, regexes skipped
/uploads/logo.PNGlocation ~* \.(png|jpe?g|webp|svg)$first matching regex (line 5), beats prefix /
/api/userslocation /api/longest prefix, no regex matched
/index.phplocation ~ \.php$first matching regex (line 6), beats prefix /
/.envlocation ~ /\.(?!well-known)first matching regex (line 7), beats prefix /
/.well-known/acme-challenge/xlocation /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.

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.

Share

Frequently asked questions

Why is my regex location ignored for some paths?
A prefix location with ^~ matched first, an exact = location matched, or an earlier regex matched before yours. Regex locations are evaluated in file order.
Does location matching include the query string?
No. Nginx matches the normalised URI path only; arguments after ? are not part of the match.
Is what I paste sent anywhere?
No. The tool runs entirely in your browser with JavaScript. Nothing you type or paste is sent to our server or stored.

Keep planning

Similar tools