Tools / Nginx Config Formatter

Nginx Config Formatter.

Beautify nginx.conf — consistent indentation, one directive per line, comments kept — and catch syntax errors.

Runs in your browser

Ctrl/⌘ + Enter to run · Ctrl/⌘ + Shift + C to copy the result

Result
Formatted config
Stats

About Nginx Config Formatter

Nginx Config Formatter rewrites an nginx configuration with consistent indentation so that nested http, server, location, upstream, map and if blocks are easy to read and to review in a diff. Paste a config squeezed onto one line, copied from a blog post or edited by several people over the years, and every directive ends up on its own line with its arguments separated by single spaces and each block indented one level deeper than its parent. The formatter tokenizes the file the way nginx does, so quoted strings, escaped characters, ${variables} and regular expressions in location blocks are copied exactly as written, and comments stay where they were, including a comment at the end of a directive line. Lua code in content_by_lua_block and similar directives is kept verbatim and only re-indented as a whole, because it is not nginx syntax. Runs of blank lines are collapsed to one, and you can drop them entirely. Because it parses the structure, the formatter also finds the mistakes that make nginx -t fail: a directive without its closing semicolon, a block that is never closed, an extra closing brace or an unterminated quote, each with the line number. A common trap it exposes is a regex location containing { or } without quotes, which nginx reads as a block brace; quote such regexes, as the example does. It does not check whether directive names or values are valid for your nginx version or modules. Everything runs in your browser.

How to Use

  1. Paste your nginx.conf or a server block.
  2. Choose the indent width and whether to keep blank lines.
  3. Copy the formatted config and run nginx -t before reloading.

Frequently Asked Questions

Does it validate directives?

It validates the structure (braces, semicolons, quotes) but not whether a directive exists or takes those arguments. Run nginx -t on the server for that.

Will it change my regular expressions or quoted values?

No. Quoted strings, regexes, variables and escapes are copied exactly; only whitespace between tokens and indentation change.

What happens to Lua blocks?

The content of *_by_lua_block directives is kept as written and re-indented as a whole, since it is Lua code rather than nginx syntax.

Is my config uploaded?

No. Formatting runs in your browser, and the page makes no network requests while you use it.

Related Tools