Nginx configuration files use a simple block syntax built from directives ending in semicolons and { } blocks that nest contexts like http, server, and location. When you edit them by hand they quickly become inconsistently indented, and a single missing semicolon or unbalanced brace will stop the server from reloading. This Nginx config formatter re-indents your file and flags those structural mistakes entirely in your browser.
How it works
The tool runs a pure-JavaScript tokenizer rather than a regex search-and-replace. It walks the source character by character, tracking whether it is inside single quotes, double quotes, or a comment, and emits a formatted statement whenever it reaches a ;, an opening {, or a closing }.
Indentation is driven by brace depth: every opening brace increases the indent level and every closing brace decreases it. Because the parser respects quoting, a # or brace inside a quoted value is treated as data, not as a comment or block boundary.
Validation rules
The formatter reports three classes of problem:
- A directive line whose text does not end in
;,{, or}— flagged as a likely missing semicolon. - A closing
}with no matching open block at that point. - Any blocks still open when the file ends, with a count of how many
}are missing.
Notes
This is a structural check, not the full Nginx grammar. It will not tell you that, for example, proxy_pass is disallowed in a particular context. Use it to clean up formatting and catch the two most common syntax errors quickly, then confirm with nginx -t before you reload. Everything runs locally, so configs containing internal hostnames stay private.