b2KIT

Nginx Config Formatter

Format and validate Nginx configuration files with proper block indentation and directive sorting.

Tested tool guide Tested browser tools Checked August 16, 2026

What Nginx Config Formatter does and how it behaves

Paste an Nginx configuration to turn unevenly spaced directives and nested blocks into a consistent layout, sort directives, and identify configuration text the formatter considers invalid. It distinguishes semicolon-terminated directives from brace-delimited contexts, so server, location, upstream, map, and similar blocks can be indented by nesting level. The common surprise is that a clean, accepted result is not equivalent to a successful `nginx -t` on the target host. Installed modules, Nginx version, included files, and referenced paths can still make the deployed configuration fail.

How the result is produced

1

Block-aware formatting

Formatting follows Nginx statement boundaries. A directive ending in a semicolon remains a statement, while an opening brace starts a nested context and its matching closing brace returns to the parent indentation. The tool also sorts directives. Review the resulting order whenever a block contains repeated directives or sequence-sensitive rules, especially around access and rewrite logic.

2

Text-level validation

Validation evaluates the pasted text as a configuration document and can expose structural mistakes such as an unfinished directive or unmatched block delimiter. It cannot inspect files named by include, confirm that certificates or keys exist, discover modules compiled into a remote Nginx installation, reproduce version-specific behavior, or resolve the effective configuration assembled from included files.

Good uses

  • Reformat a hand-edited server block before code review so location, proxy, header, and logging directives are consistently indented and easier to compare in a diff.
  • Normalize a configuration assembled from several snippets before placing it in a repository, while reviewing ordering changes to repeated access, routing, or rewrite directives.
  • Check a pasted virtual-host configuration for obvious statement and brace problems before copying it to a host and running `nginx -t` in that environment.

Limits and checks

  • Sorting is not automatically semantics-preserving. Some Nginx directives are evaluated in written order, so inspect moved repeated rules rather than treating formatting as a purely cosmetic edit.
  • The validator sees only the pasted text. An include target can be missing, unreadable, or invalid even when the visible configuration passes this check.
  • A positive result does not prove compatibility with the Nginx binary that will load the file. Directive availability, accepted parameters, and context restrictions can depend on version and compiled modules.

Common questions

Does this replace running nginx -t?

No. `nginx -t` evaluates the configuration using the actual Nginx executable and also attempts to open referenced files. This browser tool cannot see the target host's include tree, certificates, keys, permissions, installed modules, or exact build. Format and check here, then run `nginx -t` in the deployment environment before reloading Nginx. Keep the checked file identical to the file you deploy.

Can I assume the sorted output behaves exactly like the input?

No. Indentation and ordinary spacing are normally cosmetic, but reordering is a separate change. Nginx has order-sensitive constructs, including rule lists and sequences of rewrite directives. Review a diff whenever the formatter moves directives, pay particular attention to duplicates and related statements, and test the resulting file on the intended Nginx installation. Do not approve the output from appearance alone.

References and verification

The behavioral notes were checked against the browser implementation. Standards and primary references below define the relevant format, formula, or platform behavior.

Related Tools