Nginx config formatter
Format supported Nginx configuration tokens while preserving quoted content and checking balanced structure.
How it works & useful details
How it works & supported syntax
Formats a conservative Nginx token subset: semicolon directives, brace blocks, quoted strings, escapes, ${variable} references and standalone comments. It preserves the ordered token content while normalizing whitespace outside tokens. Inline comments after completed directives move onto their own lines.
Comments inside unfinished directives, unquoted brace quantifiers, embedded scripting blocks and unbalanced syntax are rejected. Quote regexes containing braces before use. Limits:100,000 input characters, 20,000 tokens, 32 nested blocks and 250,000 output characters. This is not nginx -t; directive names, contexts, files and module behavior are not validated.
Local workspace
Your input stays in this page. These tools calculate or process text; they do not run commands, start containers, contact servers or change settings on your device.
Previews pause above 20,000 combined characters. Use the action to process the full supported input. Exports contain the complete result within the tool’s stated limits.
About this tool
Nginx config formatter tidies supported Nginx configuration tokens into consistent indentation while preserving quoted values and checking that braces and directives are balanced. It is useful when reviewing a server block pasted from a ticket.
The configuration is treated as text; Nginx is not run and no configuration is applied. Constructs outside the supported token grammar are left as written and reported.
How to use it
- Paste the Nginx configuration.
- Run the formatter to indent the structure.
- Check the balance report for missing or extra braces.
- Copy the formatted configuration back to your file.
Worked example
http{server{listen 80;server_name example.test;location / {root /var/www/html;index index.html;}}}is formatted as
http {
server {
listen 80;
server_name example.test;
location / {
root /var/www/html;
index index.html;
}
}
}Each directive gets its own line and each block is indented, which makes it easy to see which location belongs to which server block. That is the most common source of confusion in hand-edited configs.
Formatting is not validation
The formatter checks that braces balance and that directives end with semicolons, and it preserves quoted strings, variables, and comments. It does not know which directives exist, which modules are loaded, or whether a directive is allowed in its context. Always run nginx -t on the server before reloading. It validates the real configuration, including included files.
Regular expressions in location blocks that contain braces, such as ~ ^/a{2}, must be quoted before formatting, as Nginx itself recommends. Embedded Lua or JavaScript blocks are rejected rather than reformatted.
Frequently asked questions
Does it validate Nginx semantics?
No. It checks structural balance and formats tokens. Directive validity depends on your Nginx build and included files.
Are comments and quoted strings preserved?
Yes. Comments and quoted content are kept exactly as written.
What is the limit?
Up to 100,000 characters of configuration text.
Can I use four spaces or tabs?
Choose two or four spaces in the tool. For tabs, convert the indentation in your editor after pasting.
