DevTools Logo

Caddyfile Builder

Caddyfile Builder

Generate and validate Caddy v2 configuration. Quoting, matchers and automatic HTTPS are handled for you.

Runs in your browser
Try an example

Site and routes

2 routes

Generated Caddyfile

4 lines · 72 chars
Automatic HTTPS: Caddy gets and renews a Let's Encrypt or ZeroSSL certificate and redirects HTTP to HTTPS. Ports 80 and 443 must be reachable and DNS must point at this server.
Caddy runs directives in its own fixed order, not the order written. Here they run as: encode → reverse_proxy. Wrap routes in handle blocks to control the order.
example.com {
  reverse_proxy /api/* localhost:3000
  encode gzip zstd
}

About

Generate deterministic nested Caddyfile routes and validate existing files locally without uploading configuration.

Examples

Reverse proxy plus static files

Input
generateCaddyfile({ siteAddress: "example.com", routes: [{ type: "reverse_proxy", path: "/api/*", upstreams: ["localhost:3000"] }, { type: "handle_path", path: "/static/*", root: "/srv/www" }] })
Output
example.com {\n  reverse_proxy /api/* localhost:3000\n  handle_path /static/* {\n    root * /srv/www\n    file_server\n  }\n}

Proxy routes emit one line with all upstreams; handle_path routes nest root and file_server in a sub-block.

Redirect with status control

Input
generateCaddyfile({ siteAddress: "example.com", routes: [{ type: "redir", from: "/old", to: "/new" }] })
Output
redir /old /new 308 (302 when permanent: false)

Redirections default to permanent 308; passing permanent: false switches the emitted status to 302.

About this tool

Caddyfile Builder generates server blocks with generateCaddyfile({ siteAddress, routes }): the address (default :80) opens the block and each route emits its directive — handle_path with root plus file_server, reverse_proxy with upstream list (default localhost:3000), basic_auth with username and password hash, encode with algorithm list (default gzip), header with sorted +set and -delete entries, and redir with from/to plus 308 by default (302 only when permanent: false).

Validation comes from validateCaddyfile(source): a brace tracker ignoring # comments and quoted strings reports Unmatched closing brace and Unclosed block: missing } errors, a site address mixed with a directive on one line is an error, and first tokens inside a block that match neither the known directive set (root, file_server, reverse_proxy, handle_path, basic_auth, encode, header, redir, respond, route, handle, log, tls, @id) nor +/- header modifiers produce Unknown Caddyfile directive warnings. Results sort by line with errors first.

Localhost HTTPS expectations are explicit via localhostHttpsNotice(siteAddress): localhost, localhost:<port>, and bare :<port> addresses return the notice that Caddy will not obtain a public HTTPS certificate there — any real domain returns null and qualifies for automatic HTTPS.

How to use this tool

  1. Set the site address

    Enter a domain for automatic HTTPS, or a localhost/bare-port address when testing locally (the tool flags the HTTPS limitation for you).

  2. Add routes

    Stack reverse_proxy upstreams, handle_path file roots, header rewrites, basic_auth, encode, and redir entries — header set/delete lines sort automatically.

  3. Validate before deploying

    Run validateCaddyfile on the output: fix Unclosed block errors and review Unknown Caddyfile directive warnings for typos.

Use cases

Fronting Node apps with Caddy

Emit a reverse_proxy block pointing at localhost:3000 behind a real domain for automatic HTTPS.

Serving static assets alongside an API

Combine a handle_path file_server root for /static/* with proxy and header routes in one site block.

Migrating legacy paths

Generate redir from/to rules with explicit 308/302 status before wiring them into the live Caddyfile.

Common mistakes

Mistake:Leaving a site block unclosed.

Fix:Every opened { needs its closing } — validateCaddyfile reports the exact opening line as Unclosed block: missing }.

Mistake:Typing a directive name slightly wrong.

Fix:Unknown names yield an Unknown Caddyfile directive warning, not an error — check the spelling against root, reverse_proxy, redir, header, encode, and friends.

Mistake:Expecting public HTTPS on localhost.

Fix:Caddy only provisions public certificates for real domains; localhost and bare ports always return the localhostHttpsNotice limitation.

Frequently asked questions

What does this tool do?

It generates a Caddy site block (reverse_proxy, handle_path with file_server, header, basic_auth, encode, and redir routes) from your address and routes, validates pasted Caddyfiles for unclosed blocks and unknown directives, and tells you when an address cannot get automatic public HTTPS.

Why does localhost show an HTTPS notice?

Caddy only provisions public certificates for real domains. localhost, localhost:<port>, and bare :<port> addresses always return the localhostHttpsNotice limitation, while any real domain returns null and qualifies for automatic HTTPS.

Is my Caddyfile uploaded or stored?

No. Generation and validation run fully client-side — brace tracking, directive checks, and text assembly never leave your browser.

How do I fix Unclosed block and Unknown directive reports?

Unclosed block names the exact opening line missing its } — add the closing brace. Unknown Caddyfile directive is a warning for a first token outside the known set (reverse_proxy, redir, header, encode, and friends), so check the spelling rather than assuming it will work.

References & standards