nginx Config Formatter
Paste an nginx configuration and get it re-indented by nesting depth, with each directive on its own line and extra blank lines collapsed.
Use the tool
Why this tool exists
Configs inherited from older servers are often a mix of tabs, spaces and one-line blocks like location /static/ { root /var/www; }. That makes a diff noisy and a missing brace easy to miss. A consistent layout makes review simpler and shows at a glance which block a directive belongs to.
This formatter places each directive and brace on its own line, indents by depth using 2 spaces, 4 spaces or tabs, and leaves comments and quoted strings alone. It works on the text only, so your config is not sent anywhere and nothing is validated against a real nginx binary.
How to use it
- Paste your nginx.conf or a single server block into the input.
- Choose an indent of 4 spaces, 2 spaces or a tab.
- Copy the formatted configuration back into your file.
Frequently asked questions
Does it change any values or comments?
No. Only whitespace and line breaks change. Comments, quoted strings and directive values are copied as they are, apart from runs of spaces outside quotes being collapsed to one.
Does it check that my config is valid?
No. It is a formatter, not a validator. Run nginx -t on the result to confirm that the syntax and the directives are correct for your build.
Why did a regex with braces confuse it?
The depth counter counts braces, so an unquoted pattern like {2,3} can throw it off. Put such patterns in quotes, which nginx accepts, and format again.
Can it handle include files?
It formats only the text you paste. Include lines are left as they are, so format each included file separately.