DevTools Logo

Nginx Location Match Simulator

Nginx Location Match Simulator

Paste location blocks and a URI to see which block wins, with the full decision trace.

Runs in your browser
nginx decodes and normalizes $uri before location matching; query strings are ignored.
Try an example

Nginx configuration

11 lines · 150 chars · 3 locations

Matching verdict

line 5

Winning location

~*\.(css|js)$ (line 5)

URI used: /static/app.css

  1. exact/static/app.css — no exact match
  2. prefix/static/app.css — /static/ (line 2, 8 bytes), / (line 8, 1 bytes)
  3. regex~* \.(css|js)$ — match (line 5)
  4. finalfirst matching regex — winner: line 5

Directives in the winning block

expires 30d

Details

A diagnostic tool for nginx location precedence. It parses server blocks and bare location lists (including quoted and brace-containing regex patterns), normalizes the request URI the way nginx does, then applies exact, longest-prefix, ^~ short-circuit and regex-in-configuration-order phases. Each phase is traced with the candidates considered and the reason for skipping regexes. Named locations are excluded, includes are flagged, and common PCRE constructs are translated; any degraded verdict is called out next to the winner. Configurations stay in the browser.

More examples

Longest prefix wins

location /docs { }
location /docs/api { }
location / { }

For /docs/api/v1 the trace shows /docs/api selected over the shorter prefixes.

^~ short-circuit

location ~ \.php$ { }
location ^~ /static/ { }

For /static/index.php the regex phase is skipped because the caret prefix already won.

Exact health check

location = /health { return 200; }
location ~ /heal { return 418; }

An exact match wins before any regex is tested, even with a query string on the URI.

Examples

Exact beats regex

Input
location = /health { }
location ~ /heal { }  —  /health?x=1
Output
winner: location = /health

The exact phase runs first and short-circuits regex evaluation.

Caret short-circuit

Input
location ~ \.php$ { }
location ^~ /static/ { }  —  /static/index.php
Output
regex phase skipped

The longest ^~ prefix wins before any regex is tried.

Encoded path

Input
/x%2f%2fy
Output
/x/y

Decoding happens before slash merging, matching nginx's $uri normalization.

About this tool

Nginx Location Match Simulator answers one question precisely: which location block handles this request URI? Paste a server block or a bare list of locations, enter a URI, and the tool walks nginx's documented precedence with a trace of every step.

Exact `=` locations win immediately. Among plain prefixes and `^~` prefixes the longest matching prefix is selected; a `^~` winner skips regular expressions entirely. Otherwise `~` and `~*` regexes are tried in configuration order and the first match wins, falling back to the longest prefix. Skipped candidates and their reasons appear in the trace.

Before matching, the URI is split from its query string, percent-decoded, slash-merged and dot-segment-resolved, mirroring the normalized `$uri` nginx uses. Traversal above root becomes a 400 outcome. Everything runs locally; pasted configuration never leaves the browser.

What this tool does not do

  • Nested locations are reported but treated as a simplified continuation rather than fully recursive matching.
  • include directives cannot be followed, so included locations are absent from the candidate set.
  • rewrite and try_files directives inside a winning block are displayed but not executed.
  • JavaScript RegExp is used after a small PCRE translation layer; exotic PCRE may diverge.
  • Configs and URIs stay in the tab; nothing is uploaded or persisted.

How to use this tool

  1. Paste the config

    Add a server block or just the location blocks. Quoted patterns and regexes containing braces are parsed correctly; comments are ignored.

  2. Enter a request URI

    Provide an absolute path such as /static/app.css?x=1. The query string is shown but excluded from matching.

  3. Set normalization

    Toggle percent decoding and slash merging. The config's own merge_slashes off directive is respected by default.

  4. Read the decision

    The verdict card names the winning block and its line. The ordered trace shows exact, prefix, regex and final phases with skipped regexes called out.

  5. Check the caveats

    Duplicate prefixes, includes, nested locations, invalid if placement and untranslatable regexes are reported, and the verdict is marked degraded when needed.

Use cases

Debug static-route bypass

Find out why a regex never sees requests already captured by a ^~ prefix.

Audit a server block

Check a large pasted config for duplicate prefixes, includes and dead regexes.

Learn precedence

Compare exact, prefix and regex locations with an explicit trace for each request.

Handle encoded URIs

See how decoding and slash merging change the URI before matching.

Location modifiers

ModifierMeaning
= /pathExact match; wins immediately over everything else
(none) /pathPlain prefix; longest matching prefix is remembered
^~ /pathPrefix that short-circuits regex evaluation when it is longest
~ regexCase-sensitive regular expression, first match in config order wins
~* regexCase-insensitive regular expression
@nameNamed location used by try_files/error_page; excluded from matching

Query strings are split off before decoding; nginx matches locations against the normalized path only.

Common mistakes

Mistake:Assuming regexes are tried before prefixes.

Fix:nginx finishes the prefix phase first; a regex only wins if no ^~ prefix took the URI.

Mistake:Treating equal-length prefixes as ambiguous.

Fix:Only one distinct prefix of a given length can match a URI; the tool warns about identical duplicated prefixes instead.

Mistake:Including the query string in a location pattern.

Fix:nginx matches locations against the path only; the query is displayed as a note.

Mistake:Expecting full PCRE support.

Fix:Common PCRE constructs are translated; anything else is skipped with a degraded-verdict warning.

Mistake:Forgetting that includes are not followed.

Fix:Included locations are not present in the pasted text, so the tool warns that the candidate set may be incomplete.

Frequently asked questions

Which wins: a prefix or a regex location?

nginx first looks for an exact (=) match, then remembers the longest matching plain or ^~ prefix. If that prefix has ^~, regex evaluation is skipped and the prefix wins. Otherwise regular expressions are tried in configuration order; the first match wins, and if none match the remembered longest prefix is used.

What does ^~ do exactly?

^~ marks a prefix location as terminal for matching purposes: when it is the longest matching prefix, nginx does not test any ~ or ~* regex locations at all. The trace spells this out with the list of regexes that were skipped.

Are regexes tried in configuration order?

Yes. The first ~ or ~* pattern that matches the normalized URI wins, so moving a broad regex above a narrow one changes the result. The trace lists each regex in the order it was tried.

What happens with duplicate prefixes?

Two identical prefix locations are a configuration error in nginx and the simulator reports it. Distinct prefixes can never be ambiguous for a single URI: only one prefix of a given length can match it.

Does the query string affect matching?

No. nginx splits the query arguments off the raw URI before location matching. The simulator shows the query as a note but matches only against the normalized path.

Is my nginx configuration uploaded?

No. Parsing, normalization and matching happen entirely in your browser tab. Configurations often reveal internal infrastructure, so nothing is uploaded, logged or persisted.

References & standards