Start a project

Tool 179 of 194 · Servers

Nginx Location Block Tester

Paste a server block and some URLs and see which location nginx picks for each one, what it does next, and why.

Nginx Location Block Tester at a glanceIllustration: 1, server { }; 2, processed in your browser; 3, Matched location.Nginx Location Block Tester</>1server { }44 × 443Matched location2In yourbrowser
1 server { } 2 processed on your device 3 Matched location

Nginx Location Block Tester

Your server block and test URLs

try_files, index and -f checks look here, because this page can't see your server.

    Which location handles each URL

    URLLocationResult

    Step by step

      Test URLs per location

      01

      What it does

      Runs nginx's location matching, rewrites, try_files and proxy_pass rules on your config for each test URL and explains every step.

      • Exact, ^~, regex (in file order) and longest-prefix matching, as nginx does it
      • Nested and named (@) locations
      • rewrite with last, break, redirect and permanent, and return
      • try_files, index, alias and root against files you list

      02

      Private by design

      Everything happens in your browser. Nothing you type, paste or upload is sent anywhere, and it keeps working offline once the page has loaded.

      03

      What you get

      The matched location, result and step-by-step trace per URL, with a Copy and a Download button on every result.

      • nginx
      • Servers
      • Config
      • Debugging

      Why it matters

      nginx doesn't pick a location by reading top to bottom. It looks for an exact match first, then remembers the longest prefix, checks any locations nested inside it, then tries regex locations in the order they appear, and the first regex that matches wins over the prefix, unless the prefix was marked ^~. Add try_files falling back to a PHP front controller, an alias with a missing slash or a proxy_pass with a trailing slash, and it's easy to be sure a request goes one place when it goes another.

      This tester runs that algorithm on your config. For each URL it shows the location chosen and why, then follows the server and location rewrites, the if blocks it understands, return, try_files and index against a list of files you say exist, and works out the final file path or the upstream URL proxy_pass would request, including internal redirects back through the location search. It's one server block and the common directives, run in your browser; for the last word, nginx -t and a test request still decide.

      How it works

      1. InputA server block and test URLs
      2. In your browsernginx's own location order, then rewrites and try_files
      3. OutputThe block, result and every step per URL

      Where it fits in a designer's workflow

      1. Plan
      2. Design
      3. Build
      4. Test
      5. Launch
      Checking a config change before you reload nginx.

      By the numbers

      Which location answers each of the sample's 9 test URLslocation ~ \.php$: 2 URLs; location = /: 1 URL; location ^~ /static/: 1 URL; location ~* \.(png|jpe?g|webp|avif|svg)$: 1 URL; location ~ ^/images/private/: 1 URL; location /api/: 1 URL; —: 1 URL; location /: 1 URLlocation ~ \.php$2 URLslocation = /1 URLlocation ^~ /static/1 URLlocation ~* \.(png|jpe?g|webp|avif|svg)$1 URLlocation ~ ^/images/private/1 URLlocation /api/1 URL—1 URLlocation /1 URL
      Worked out by this tool from its sample server block. Two URLs that look like they belong to location / end up in the PHP regex location: /guides/oak-care falls back through try_files to /index.php, and the search runs again; /images/oak-table.webp is under the /images/ prefix, but the image regex is checked afterwards and wins. Source: nginx docs: location; nginx docs: try_files.
      Show the numbers as a table
      URLLocationResult
      /location = /200 file /var/www/shop/public/index.html
      /static/img/logo.pnglocation ^~ /static/200 file /var/www/shop/assets/img/logo.png
      /images/oak-table.webplocation ~* \.(png|jpe?g|webp|avif|svg)$200 file /var/www/shop/public/images/oak-table.webp
      /images/private/invoice.pnglocation ~ ^/images/private/403
      /api/orders?page=2location /api/Proxied to 127.0.0.1:3000/v2/orders?page=2
      /old-shop/tables?sort=price—301 → /shop/tables?sort=price
      /guides/oak-carelocation ~ \.php$Proxied to unix:/run/php/php8.3-fpm.sock (SCRIPT_FILENAME /var/www/shop/public/index.php)
      /about/location /200 file /var/www/shop/public/about/index.html
      /admin.phplocation ~ \.php$Proxied to unix:/run/php/php8.3-fpm.sock (SCRIPT_FILENAME /var/www/shop/public/admin.php)

      How to use it

      1. Paste the server block (or a whole nginx.conf: the first server block is used).
      2. List the URLs to test, and the files that exist under root.
      3. Read the matched location and result for each URL.
      4. Pick a URL to see every step nginx takes.

      FAQ

      In what order does nginx check location blocks?

      Exact (=) locations first. Then it finds the longest matching prefix and checks locations nested inside it. If that prefix has ^~, it stops; otherwise it tries regex locations (~ and ~*) in the order they appear in the file and uses the first match. If no regex matches, the longest prefix is used.

      Why does my regex location win over a longer prefix?

      Because regexes are checked after prefixes and override them, however long the prefix. Mark the prefix location ^~ to stop regex checking for URLs under it.

      What does the trailing slash in proxy_pass change?

      With a URI part (a path after the upstream address, such as app:3000/v2/) the matched location prefix is replaced by that path. Without one (just app:3000) the original request URI is passed unchanged. In a regex location a URI part is a config error.

      Why do I have to list files?

      try_files, index and -f checks depend on what's on disk, which this page can't see. List the paths that exist and the tester follows the same branches nginx would.

      Does it support every directive?

      No. It covers location matching, rewrite, return, set, a subset of if, try_files, index, root, alias, proxy_pass and fastcgi_pass. Includes and maps aren't read; anything else is ignored. Regexes run as JavaScript, and PCRE-only syntax is flagged.

      Work with me

      Want a site that gets these right?

      I build fast, accessible websites and web apps that pass these checks from day one. Tell me about your project and I'll reply personally with honest next steps.

      All developer tools · Back to leej.uk