Nginx Config Formatter
Format nginx configuration: one directive per line, nested blocks indented, comments and quoted strings kept. Detects unclosed blocks and missing semicolons.
Runs entirely in your browser. Your data is never uploaded.
Related Tools
View AllWhat is Nginx Config Formatter?
The Nginx Config Formatter re-indents nginx configuration files: every directive goes on its own line, blocks such as server and location are indented, and blank lines are reduced to at most one. It also reports structural mistakes – unbalanced braces, unterminated quotes and directives missing their ;.
How to use Nginx Config Formatter
- Paste your nginx configuration (nginx.conf or a server block).
- Choose the Indentation (4 spaces is the nginx convention).
- Click Format (the output also updates while you type).
- Fix any reported error, then copy or download the result.
Example
server{listen 80;server_name example.com; # main
location / {root /var/www;}} server {
listen 80;
server_name example.com; # main
location / {
root /var/www;
}
} When to use Nginx Config Formatter
Use it to tidy configs copied from tutorials, review changes, or find the missing brace or semicolon reported by nginx -t. It checks structure only – it cannot tell whether a directive is valid in a context; always run nginx -t before reloading.
How Nginx Config Formatter works
A tokenizer splits the text into words, quoted strings ("…" and '…'), ${variables}, # comments, braces and semicolons, tracking line and column. The printer outputs each directive as its words joined by single spaces followed by ;, opens blocks with { and closes them on their own line. Comments that followed a directive on the same line stay on that line. Quoted strings and regular expressions are copied verbatim. The formatter does not know directive names, so it never changes your arguments.
Common Use Cases
- Cleaning up a one-line or badly indented server block
- Finding an unclosed location block
- Normalising configs before committing to Git
- Formatting config snippets for documentation
Security Note
Everything runs locally in your browser; the code you paste is not uploaded.
FAQs
Does it validate directive names?
No. It checks braces, quotes and semicolons only. Use nginx -t for full validation.
Are comments kept?
Yes, including comments at the end of a directive line.
What about Lua blocks (content_by_lua_block)?
They are tokenized like nginx syntax, so Lua code inside may be reflowed; keep such files out of the formatter.