01What is Nginx Location Tester?
nginx doesn't pick location blocks in the order you write them. That surprises a lot of people, and it's behind many "why is this route serving the wrong thing" bugs. Give this tester a request URI and a list of location lines, and it walks through the selection order described in the official ngx_http_core_module documentation. Exact matches (=) are checked first. If the URI is identical to the pattern, that block wins on the spot. Next, every prefix location, plain or ^~, is compared, and the longest one that matches is remembered. If that longest prefix carries ^~, the search stops there and regexes are skipped. Otherwise regex locations (~ for case-sensitive, ~* for case-insensitive) are tried in the order you listed them, and the first match wins. If no regex matches, the remembered longest prefix is used. The winner appears in the Matched Location box with a short reason. Below it, Match Evaluation Order lists every directive as matched or not, with the reason. You'll see prefix lengths, failed comparisons and invalid regex warnings there. Before matching, the URI is normalised the way nginx does it. The query string and fragment are dropped, %XX escapes are decoded, repeated slashes are merged and . and .. segments are resolved. The tool shows the normalised path whenever it differs from what you typed. So /static/../admin//panel?x=1 is tested as /admin/panel. You can paste lines straight from nginx.conf. A trailing { is fine and the block body is ignored. Quoted patterns work as well, which nginx needs when a regex contains { or ;, as in location ~ "^/[0-9]{4}/". A worked example: take the URI /api/v2/users/123 with = /api, /api/v2/, ^~ /api/ and ~ ^/api/v[0-9]+/. The exact match fails. Both prefixes match, and /api/v2/ is the longer one. It has no ^~, so regexes still run, and ^/api/v[0-9]+/ wins. People often expect ^~ /api/ to block that regex. It only does so when it is the longest matching prefix. Some honest limits. Regexes run in JavaScript's engine, not PCRE. They agree on everyday patterns, but PCRE-only syntax such as (?P<name>...) shows up as an invalid regex. Nested locations, named locations like @fallback, and server or if blocks aren't modelled. Prefix matching here is case-sensitive, as on Linux builds. For anything unusual, confirm with nginx -T and a curl request against a real server.
Sysadmins and backend developers who need to know which nginx location block will handle a given request before they reload the server. The tool runs entirely in your browser, so your data never leaves your device.
02How to use Nginx Location Tester
- Type the path into Request URI, for example /assets/css/main.css.
- Paste your location lines into Location Directives (one per line), copied straight from nginx.conf if you like.
- Read the Matched Location box for the winner and the reason.
- Scan Match Evaluation Order to see how every other directive was judged.
- Load Basic Matching, API Routes or Static Files to see typical precedence puzzles.
03Worked examples
- Input:
URI /images/logo.png; locations: = /, /images/, ~* \.(png|jpg|gif)$, / - Result:
Winner: location ~* \.(png|jpg|gif)$ (Regex (case-insensitive) matched. First matching regex wins.) - The plain prefix /images/ also matches, but a matching regex overrides an ordinary prefix.
- Input:
URI /assets/css/main.css; locations: /, /assets/, ~* \.css$, ^~ /assets/css/ - Result:
Winner: location ^~ /assets/css/ (Prefix match. URI starts with "/assets/css/" (length: 12). Preferential prefix (^~) stops regex search.) - Because the longest prefix carries ^~, the \.css$ regex is never checked.
- Input:
URI /api/v2/users/123; locations: = /api, /api/v2/, ^~ /api/, ~ ^/api/v[0-9]+/ - Result:
Winner: location ~ ^/api/v[0-9]+/ (Regex matched. First matching regex wins.) - ^~ only blocks regexes when it is the longest matching prefix; here /api/v2/ is longer, so regexes are still tried.
- Input:
URI /static/../admin//panel?x=1; locations: /admin/, /static/, / - Result:
Normalized URI /admin/panel; winner: location /admin/ - The query string is dropped, .. is resolved and the double slash merged before matching.
- Input:
URI /docs; locations: /docs/, / - Result:
Winner: location / (Prefix match. URI starts with "/" (length: 1). No regex matched; using longest prefix.) - /docs does not start with /docs/, so the trailing-slash prefix does not match.
04Common use cases
- Working out why requests for /api/v2/users are being served by a static-file regex block
- Checking a new location ~* \.(css|js)$ caching rule won't hijack routes proxied to a Node or PHP backend
- Reviewing an inherited nginx.conf before a migration to see which block handles each route
- Seeing how a URI with ../ segments or double slashes resolves before it reaches your locations
- Deciding whether a static prefix needs ^~ to keep regex rules away from it
- Teaching teammates how =, ^~, ~ and ~* interact
05Tips
- Location matching never sees the query string. If you need to route on ?param=value, use map or if with $arg_param instead.
- /docs/ doesn't match a request for /docs. If you want both, add location = /docs or drop the trailing slash.
- Regex order matters but prefix order doesn't, so put the most specific regex locations first.
- Use ^~ on static asset prefixes like /static/ when you want to skip regex checks entirely for those paths.
- Nested locations and named locations (@fallback) aren't modelled here, so test those against a real nginx with nginx -T and curl.
06Related concepts
nginx location, Reverse proxy, Regex matching, Request routing, PCRE.
Frequently Asked Questions
What is Nginx Location Tester?
Nginx Location Tester is a free, browser-based developer tool on AIDToolStack. Test nginx location block matching It requires no installation or sign-up and works entirely in your browser.
Is Nginx Location Tester free to use?
Yes. No sign-up, no fees and no usage cap.
Does Nginx Location Tester store my data?
No. It runs in your browser; nothing is uploaded.