Home / Configs / Servers / Caddyfile reverse proxy

Caddyfile reverse proxy: example and generator

Send visitors to an app on port 3000 and get HTTPS certificates automatically.

For any system that runs Caddy 2. The file path /etc/caddy/Caddyfile is the Linux package default.

Caddy is a web server that gets and renews HTTPS certificates for you. A reverse proxy config is only a few lines: your domain, and the port your app listens on. Fill in both below, then follow the steps.

Create your config file

Type your own values. The file below updates as you type, and nothing you type leaves your browser.

Use localhost for local testing
Where your app listens

/etc/caddy/Caddyfile
example.com {
  encode zstd gzip
  reverse_proxy 127.0.0.1:3000
}

How this setup works

Diagram: Browser, then Caddy, then Your app
Browser (https://your-domain) → Caddy (ports 80 and 443) → Your app (your port)

Step-by-step setup

  1. Start your app so it listens on 127.0.0.1:3000.
  2. Install Caddy from caddyserver.com/docs/install.
  3. Save the config above as /etc/caddy/Caddyfile.
  4. Check it: caddy validate --config /etc/caddy/Caddyfile.
  5. Apply it: sudo systemctl reload caddy.

What the important lines mean

Common errors and how to fix them

502 Bad Gateway
Caddy cannot reach your app. Check the app is running on port 3000.
The certificate is not issued
The domain must point to this server, and ports 80 and 443 must be open to the internet. Check sudo journalctl -u caddy for the reason.
bind: address already in use
Another program, often nginx or Apache, already uses port 80 or 443. Stop it or move it to another port.

Frequently asked questions

Do I need certbot with Caddy?
No. For a public domain that points to your server, Caddy requests and renews certificates on its own. Ports 80 and 443 must be reachable from the internet.
Does Caddy support WebSockets?
Yes. The reverse_proxy line handles WebSocket connections without extra settings.
Can I use this on localhost?
Yes. Use localhost as the domain. Caddy then uses its own local certificate, so your browser may ask you to trust it.

Written for: Caddy 2 on Linux · Updated 2026-10-11

Free tools that help

Fix a problem with this setup

More server configs

See all 41 config generators