Free nginx and Caddyfile Formatter
Paste a messy server config to get clean indentation, a list of every directive with what it does, and the exact line of any syntax slip.
What is a nginx and Caddyfile Formatter?
nginx and Caddy are two of the most popular web servers, and both are configured in text files of directives and braces. This formatter re-indents an nginx config or a Caddyfile, lists every directive with a short explanation, and points to the line of any syntax mistake.
Each format has its own tokenizer. nginx directives end with semicolons and can quote arguments in single or double quotes. Caddyfile directives end at the line break, braces only count as structure when they stand alone, and placeholders such as {uri} stay part of their word. Output follows each project’s convention: four spaces for nginx, tabs like caddy fmt.
Key Features
One Directive per Line
Blocks squeezed onto one line, such as location / followed by a brace and two directives, are split out and indented by depth. Single blank lines between blocks are kept.
What Each Directive Does
The table lists every directive with its line number, arguments and a one-line meaning for the common ones, from proxy_pass to reverse_proxy.
Syntax Errors by Line
A missing semicolon, an unclosed brace or quote, or a stray closing brace is reported with the line to fix, before nginx -t or caddy validate complains.
Quotes and Placeholders Respected
Semicolons inside a quoted header value, regex locations, nginx variables and Caddy placeholders are kept intact rather than treated as structure.
Server Configs Stay Private
Formatting happens in your browser, so hostnames, internal addresses and certificate paths aren’t uploaded.
Perfect for everyone
- Sysadmins and DevOps engineers editing server configs
- Developers deploying behind nginx or Caddy
- Anyone cleaning up a config copied from a tutorial
How to Use the nginx and Caddyfile Formatter
Pick the format, paste the config, and copy the clean version back.
Choose nginx or Caddyfile
nginx configs live in files like nginx.conf and sites-available, and end directives with semicolons. A Caddyfile has no semicolons and puts one directive per line.
Paste the Config
Paste a whole file or a single server block. Comments are kept and moved to the indentation of the code around them.
Fix Any Reported Line
If a semicolon, brace or quote is missing, the error names the line. Fix it in the source box and the formatted output reappears.
Copy It Back and Test
Copy the formatted config into place, then run nginx -t or caddy validate on the server before reloading.
Configs Before and After Formatting
Each answer is the exact output this formatter gave for the config on the left, in the mode on the chip, or the error it reported. Spot the problem before you reveal it.
“server { listen 80; server_name example.com; location /api/ { proxy_pass http://127.0.0.1:3000; } }”
“location /api/ { proxy_pass http://app; proxy_set_header Host $host; }”
“add_header Content-Security-Policy "default-src 'self'; img-src *";”
“location ~* \.(css|js)$ { expires 30d; }”
“server { listen 80; root /var/www }”
“server { listen 80; location / { root /var/www; }”
“example.com { encode gzip @api path /api/* handle @api { reverse_proxy localhost:3000 } file_server }”
“www.example.com { redir https://example.com{uri} permanent }”
“example.com { reverse_proxy localhost:8080”
“example.com { reverse_proxy localhost:8080 }”
nginx and Caddyfile Syntax Side by Side
The two formats look alike but follow different rules. These ten differences explain most formatting errors.
nginx Directives End in Semicolons
Every simple nginx directive, such as listen 80, must end with a semicolon. Block directives such as server end with a closing brace instead.
“Does server need a semicolon after its closing brace?”
Caddyfile Directives End at the Line
A Caddyfile has no semicolons; the line break ends a directive. Putting two directives on one line merges them into one.
“How do you separate two Caddy directives?”
Contexts Nest in nginx
nginx directives live in contexts: main, events, http, server, location and upstream. A directive placed in the wrong context fails nginx -t.
“Which context holds server blocks?”
Site Blocks Start a Caddyfile
Each Caddy site block begins with one or more addresses, such as example.com, followed by a brace. A lone brace at the very top is the global options block.
“What is a block with no address at the top of a Caddyfile?”
Location Matching in nginx
location /path matches by prefix, location = /path exactly, and location ~ or ~* by case-sensitive or case-insensitive regex.
“Which location modifier makes a regex case-insensitive?”
Matchers in Caddy
A named matcher such as @api path /api/* is defined once and used by directives in that site. The at sign marks the name.
“How do you reuse a path match in Caddy?”
Variables and Placeholders
nginx writes variables like $host and $request_uri. Caddy writes placeholders in braces, such as {host} and {uri}, inside arguments.
“How does Caddy refer to the request URI?”
Quoting Arguments
Both formats quote arguments containing spaces. nginx accepts single or double quotes, and Caddy accepts double quotes or backticks.
“Which quote characters does Caddy accept?”
Including Other Files
nginx uses include with a path or glob, such as include sites-enabled/*. Caddy uses import with a file or a named snippet.
“What is nginx’s include in Caddy?”
Comments Start With a Hash
In both formats, a hash starts a comment that runs to the end of the line. Inside quotes it’s just a character.
“Is # inside a quoted string a comment?”
Common nginx Patterns in Caddy
Moving a site between the two servers is mostly a matter of translating a few blocks.
Reverse Proxy
nginx’s location / with proxy_pass http://127.0.0.1:3000 becomes reverse_proxy 127.0.0.1:3000 in a Caddy site block. Caddy sets the forwarding headers for you.
Static Site
nginx’s root plus try_files becomes root * /srv/site and file_server in Caddy. Add try_files for single-page apps.
HTTPS Certificates
nginx needs ssl_certificate paths and a renewal job, while Caddy obtains and renews certificates automatically for public domains.
Redirects
nginx’s return 301 https://example.com$request_uri becomes redir https://example.com with the uri placeholder appended, plus permanent.
Compression
nginx’s gzip on and gzip_types become encode gzip zstd in Caddy, which picks sensible content types itself.
Load Balancing
An nginx upstream block of servers becomes several addresses after reverse_proxy, with lb_policy inside its block.
Config Mistakes That Break Reloads
These are the usual reasons nginx -t or caddy validate fails.
A Missing Semicolon in nginx
Leaving the semicolon off one directive makes nginx read the next line as more arguments. The error often points at the line after the real mistake.
Unbalanced Braces
A brace left open at the end of a location block swallows every block after it. Formatting makes the wrong nesting visible at once.
proxy_pass With and Without a Trailing Slash
proxy_pass http://app/ replaces the matched location prefix, while proxy_pass http://app keeps it. Check which one your upstream expects.
add_header Inheritance
An add_header inside a location replaces all add_header lines from the server level, rather than adding to them. Repeat security headers where needed.
Caddy Directive Order
Caddy sorts directives by a built-in order, not the order you wrote. Use route or handle blocks when the written order must be kept.
Semicolons in a Caddyfile
Habit from nginx adds semicolons to Caddy lines, which then become part of the arguments. The formatter flags files that look like nginx.
Tabs Versus Spaces
Neither server cares about indentation, but mixed indentation hides nesting mistakes. Format the whole file before reviewing it.
Reloading Without Testing
Run nginx -t or caddy validate before reloading. A failed reload can leave a server down, while a tested config switches over cleanly.
When to Format a Server Config
Whenever a config is hard to read, and before every reload.
Cleaning Up a Tutorial Snippet
Configs copied from blog posts arrive with broken indentation. Format them before pasting into production files.
Finding a Syntax Error
When nginx refuses to reload, paste the file to find the missing semicolon or brace by line number.
Reviewing a Config Change
Format both versions the same way before diffing them, so the review shows real changes, not whitespace.
Learning What a Config Does
The directive table explains each line of an inherited config, from upstream blocks to try_files.
Migrating From nginx to Caddy
Read the nginx directives, then write the Caddy equivalents and format both to compare.
Documenting a Setup
Clean configs are easier to quote in runbooks and pull requests, and easier for teammates to follow.
Checking a Container Image
Before baking a config into a Docker image, format and check it so a typo doesn’t ship.