Nginx Location Tester

Paste your nginx config and test URLs to see which location block handles each one, and why

No location blocks found yet. Paste a server block, or lines like location /api/ { ... }.

Runs in your browser; your config isn't sent anywhere. Regexes run with JavaScript's engine, which agrees with nginx's PCRE for the patterns configs use; PCRE-only syntax is flagged. Rewrites, if blocks and try_files aren't followed. Moving from Apache? Try the .htaccess to Nginx Converter, and test patterns in the Regex Tester.

Was the Nginx Location Tester helpful?

Get new tools in your inbox

About once a month, when new tools ship. No spam, one-click unsubscribe.

We store only your email to send these updates. Privacy

About this tool

The Nginx Location Tester shows which location block nginx picks for a URL, and why. Paste a server block (or just the location blocks), list the URLs you care about, and each one is matched the way nginx does it: exact (=) locations first, then the longest matching prefix, then the regex locations in the order they appear, unless the longest prefix has ^~, which skips the regexes. Each result names the block and its line, explains the decision in a sentence, and lists every step: which prefixes matched and how long they were, and which regexes were tried before one matched. Regex captures ($1, $2) and named captures are shown, so you can check what a rewrite or proxy_pass will receive. Nested locations are searched the way nginx searches them, and a request for /api against a location /api/ that proxies gets the 301 redirect nginx really sends. The config is also checked for the mistakes that stop nginx starting or behave unexpectedly: duplicate locations, missing braces and semicolons, nested locations outside their parent, and PCRE-only regex syntax. Everything runs in your browser.

When to use it

  • →Finding out why a request goes to the wrong location block
  • →Checking a new regex location before reloading a production server
  • →Making sure static files, the API and the app routes each land where they should
  • →Understanding ^~, = and regex priority while learning nginx

Tips

  • ◆Regex locations are tried in config order and the first match wins, not the longest. Put specific regexes above general ones.
  • ◆Use ^~ on prefix locations like /static/ so a broad regex such as \.(png|jpg)$ can't take those requests away.
  • ◆location = / is the fastest match for the home page, because nginx stops searching immediately.
  • ◆Quote any regex that contains { or }, such as "^/\d{3}$", or nginx reads the brace as the start of the block.
  • ◆Locations match the decoded path without the query string, so ?page=2 never affects which block is chosen.

Frequently asked questions

In what order does nginx check location blocks?

First it looks for an exact match (location = /path). Then it finds the longest prefix location that matches. If that prefix has ^~, it uses it. Otherwise it tries the regex locations (~ and ~*) from top to bottom and uses the first that matches; if none does, it uses the longest prefix.

What's the difference between ~ and ~*?

Both are regex locations. ~ is case-sensitive and ~* is case-insensitive, so ~* \.png$ matches both logo.png and LOGO.PNG.

What does ^~ do?

It marks a prefix location as final: if it's the longest matching prefix, nginx uses it without trying any regex locations. It's the usual way to keep /static/ or /media/ away from regex rules.

Why does /api redirect to /api/?

When a prefix location ends in a slash and passes requests on with proxy_pass, fastcgi_pass or similar, nginx answers a request for the path without the slash with a 301 redirect to the slashed path. Add location = /api if you want to handle it differently.

Does the query string affect location matching?

No. nginx matches locations against the normalized path: decoded, without the query string, with repeated slashes merged and ./ and ../ resolved. To route on query parameters, use $arg_name in a map or an if.

Is my config sent anywhere?

No. The config is parsed and the URLs are matched in your browser.

Related tools

ToolNinja