Nginx Config Formatter

Paste a messy or minified Nginx configuration and get it back with correct indentation, consistent braces and semicolons, and all comments preserved.

FreeOnline Tool
Loading…

How to Use

  1. Paste your Nginx configuration, whether a full nginx.conf or a single server block, into the box on the left.
  2. Click the "Format" button.
  3. The formatted configuration appears on the right with proper indentation and line breaks.
  4. Check that the result looks the way you expect, then copy it for use.

Features

  • Fixes indentation so the nesting of the configuration is immediately clear.
  • Normalizes the placement and spacing of braces and semicolons.
  • Keeps existing comments intact and does not alter the meaning of the configuration.
  • Works with a complete nginx.conf as well as standalone server or location blocks.
  • The formatted output can be copied straight into your production configuration.

Use Cases

Preparing a config for review
Format the configuration before a code review so reviewers can see the structure of server blocks and location rules and spot problems faster.
Cleaning up legacy configs
Reformat an old configuration whose indentation has drifted over the years, making it far less risky to modify later.
Studying an example config
Format a snippet you found online to see clearly how server, upstream, and location directives nest inside one another.
Keeping a team config consistent
Run every configuration change through the same formatter so the style stays uniform and git diffs show only real changes.

FAQ

Can I use the formatted config as-is?
Yes. Formatting only changes whitespace and indentation, never the syntax or meaning of a directive. Still, run nginx -t to validate the file before applying it to a production server.
How does Nginx decide which location block wins?
In priority order: = exact match, then ^~ prefix match, then ~ or ~* regex match, then the longest ordinary prefix match. Formatting never changes the order of your location blocks.
How do I set up HTTPS in Nginx?
Inside the server block add listen 443 ssl; ssl_certificate /path/to/cert.pem; ssl_certificate_key /path/to/key.pem; and pair it with a server block that redirects HTTP traffic to HTTPS. The formatter helps keep that structure readable.
Does it handle OpenResty configuration?
Yes. OpenResty extends Nginx and uses the same configuration format, so configs containing lua_* directives format correctly too.