DevToolbox

Free Online Nginx Config Formatter & Generator

Format, validate, and generate Nginx configuration files online. Includes templates for static sites, reverse proxies, PHP-FPM, and HTTPS redirects — 100% client-side.

100% Client-Side · Your data never leaves your browser
Formatted output will appear here

How to Use Nginx Config Formatter & Generator

Paste your Nginx configuration into the Input pane on the left and use the toolbar to format or validate it.

  • Format — re-indents your config with consistent spacing (choose 2 or 4 spaces), normalizes whitespace between tokens, and strips excessive blank lines. Press Ctrl/Cmd+Enter to run.
  • Validate — checks for brace mismatches, missing semicolons on common directives, catch-all server names without explanatory comments, and other common mistakes. Errors appear in red below the editor; warnings appear in amber.
  • Load template — pick a ready-made configuration (Static Site, Reverse Proxy, PHP-FPM, or HTTPS Redirect) as a starting point. Templates are complete, production-ready examples you can adapt to your needs.

The formatted output is syntax-highlighted: block names appear in blue, directives in violet, values in emerald, and comments in grey. Use the Copy button to copy the result to your clipboard. Press Ctrl/Cmd+K to clear both panes.

Frequently Asked Questions

What is the structure of an nginx.conf file?

An nginx.conf file is composed of nested blocks called contexts: the main context holds global settings, the http context contains web-serving directives, and inside http you define one or more server blocks. Each server block can contain location blocks that match URL patterns and define how nginx handles matching requests. Directives outside a block apply globally; directives inside a block apply only to that context.

What is the difference between a server block and a location block?

A server block (also called a virtual host) defines how nginx responds to requests for a particular hostname and port, set via the server_name and listen directives. A location block inside a server block further refines behaviour based on the request URI — for example, serving static files for /assets/ and proxying API calls for /api/. You can have multiple server blocks and multiple location blocks inside each.

How does proxy_pass work in nginx?

The proxy_pass directive forwards incoming requests to another server or upstream group. If you write proxy_pass http://127.0.0.1:3000, nginx acts as a reverse proxy, relaying requests to your Node.js (or any other) application and returning its responses to the client. Use proxy_set_header directives alongside it to forward the original client IP and other important headers.

What is an upstream block in nginx?

An upstream block defines a group of backend servers that nginx can distribute load across. You list servers with the server directive inside upstream, and nginx supports several load-balancing algorithms including round-robin (the default), least_conn, and ip_hash. You then reference the upstream group by name in proxy_pass.

How does try_files work?

try_files checks whether files or directories exist in the order you list them and serves the first match. The final argument is a fallback — usually a named location like @app or a status code like =404. For single-page applications (React, Vue, Angular), try_files $uri $uri/ /index.html ensures the client-side router handles all routes.

How do regex location blocks work?

nginx supports regex-based location matching using ~ (case-sensitive) and ~* (case-insensitive). For example, location ~* \.(jpg|png|gif)$ matches all image URLs. nginx evaluates locations in a specific priority order: exact matches (=) first, then longest prefix strings, then regex matches in the order they appear in the config. Understanding this order is key to avoiding unexpected routing behaviour.

What are the most common nginx configuration mistakes?

The most frequent mistakes are: missing semicolons at the end of directives (nginx will refuse to start), mismatched curly braces, using root inside a location block where alias is more appropriate (root appends the full URI, alias replaces the matched portion), forgetting proxy_set_header Host $host which causes the backend to receive the wrong hostname, and setting worker_processes to a value other than auto (which automatically matches CPU core count).

Related Tools