Caddy Reverse Proxy Setup: Automatic HTTPS on a VPS
Caddy gets a certificate for your domain and proxies traffic to your app with a two-line config. Here is the full setup on a Linux VPS, plus the mistakes that break it.

Infrastructure & Support Team
On this page
A Caddy reverse proxy setup comes down to three steps: point a domain at your server, open ports 80 and 443, and write a Caddyfile with the domain and a reverse_proxy line. Caddy then fetches a TLS certificate, redirects HTTP to HTTPS and renews the certificate in the background. There is no certbot, no cron job and no separate renewal hook.
This guide walks through the whole thing on a Linux VPS: installing Caddy, proxying one or more apps, the gotchas that cause most failed certificate requests, and when Nginx is still the better choice. If you do not have a server yet, our VPS hosting plans give you root access, which is all you need here; the NVMe VPS and Intel VPS pages list the hardware options.
What a reverse proxy does for a self-hosted app#
Your app (a Node.js service, a Docker container, a dashboard) usually listens on a local port like 3000 or 8080. You do not want to expose that port directly: it speaks plain HTTP, has no certificate and is awkward to remember. A reverse proxy sits on ports 80 and 443, terminates TLS, and forwards each request to the right local port based on the hostname.
Caddy does this with very little configuration because HTTPS is on by default. According to the Caddy documentation, it enables HTTPS automatically whenever the site address in the Caddyfile is a domain name, and it redirects HTTP to HTTPS for you.
Before you start: DNS and ports#
Automatic HTTPS only works if Caddy can prove to a certificate authority that it controls the domain. The Caddy docs list what must be true for a public domain:
- The A (and AAAA, if you use IPv6) record points to your server. Your domain registrar or DNS panel is where you set that.
- Ports 80 and 443 are reachable from the internet and Caddy can bind to them.
- Caddy's data directory is writable and persistent, because certificates and keys are stored there.
A bare IP address or names like localhost, .local and .internal will not get a public certificate. Use a real domain, and wait until the DNS record resolves before you start Caddy, otherwise the first attempts fail and you waste retries.
Open the ports in your firewall as well. On Ubuntu with UFW that is sudo ufw allow 80/tcp and sudo ufw allow 443/tcp. Our firewall configuration guide covers the basics. If your backend runs in Docker, read why published Docker ports bypass UFW first, because you will want the app bound to 127.0.0.1 only and Caddy to be the single public entry point.
Caddy reverse proxy setup: install Caddy on Ubuntu or Debian#
Use the official Caddy package repository so you get updates through apt. These are the commands from the Caddy install page for stable releases on Debian and Ubuntu:
sudo apt install --yes debian-keyring debian-archive-keyring apt-transport-https curl
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo chmod o+r /usr/share/keyrings/caddy-stable-archive-keyring.gpg
sudo chmod o+r /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install caddyThe package starts Caddy as a systemd service named caddy. The config file is /etc/caddy/Caddyfile, and you apply changes without dropping connections using sudo systemctl reload caddy. Either distro works with these commands.
A basic Caddyfile with automatic HTTPS#
Suppose your app listens on 127.0.0.1:3000 and app.example.com points to your server. Replace the contents of /etc/caddy/Caddyfile with:
app.example.com {
reverse_proxy 127.0.0.1:3000
}Then reload:
sudo systemctl reload caddyThat is the entire setup. Caddy obtains a certificate for app.example.com, serves HTTPS on port 443 and forwards requests to your app. By default it uses Let's Encrypt and ZeroSSL, and if one fails it falls back to the other.
To confirm it worked, run curl -I https://app.example.com from your laptop. You should see a normal response from your app over HTTPS, and curl -I http://app.example.com should return a redirect to the HTTPS address.
Proxying several apps on one server#
One Caddy instance can handle as many hostnames as you like. Each site block gets its own certificate:
app.example.com {
reverse_proxy 127.0.0.1:3000
}
status.example.com {
reverse_proxy 127.0.0.1:3001
}
api.example.com {
reverse_proxy 127.0.0.1:8080
}This is how you can run several self-hosted tools, for example a Node.js app behind a proxy and a monitoring dashboard, on one small VPS. Each needs its own DNS record, and all of them can point to the same IP address.
You can also list several upstreams in one reverse_proxy line. Caddy then load balances between them, using a random policy by default, with round_robin, least_conn and others available. Retries are off by default and health checks are opt-in.
What Caddy forwards to your app#
By default, Caddy sets X-Forwarded-For, X-Forwarded-Proto and X-Forwarded-Host on the proxied request, and it ignores incoming values for them to prevent spoofing. Your app therefore sees the real client IP in X-Forwarded-For and knows the original request was HTTPS.
Two practical points follow from this:
- Configure your framework to trust the proxy. Many apps (Express, Django, Rails, Laravel) ignore forwarded headers until you tell them the proxy is trusted, and will log
127.0.0.1as every visitor. - If you put another proxy or CDN in front of Caddy, for example Cloudflare, Caddy discards that proxy's forwarded headers unless you list its ranges under
trusted_proxies.
WebSockets work without extra configuration: reverse_proxy handles the upgrade and tunnels the connection. One detail to know is that by default WebSocket connections are closed when you reload the config, so a reload will drop live chat or dashboard sessions. The stream_close_delay option exists to soften that.
Why Caddy is not getting a certificate#
Almost every failed issuance traces back to the same few causes. Start with the logs:
journalctl -u caddy --no-pager | less +GThen check these in order:
- DNS does not point at this server. Run
dig +short app.example.comand compare it with your server's public IP. A recent change may not have propagated yet. - Ports 80 or 443 are blocked. Check the host firewall and any provider-level firewall. Test from outside with
curl -I http://app.example.com. - Another service already holds port 80 or 443. If Nginx or Apache was installed earlier, stop and disable it, or Caddy cannot bind.
sudo ss -tlnp | grep -E ':80|:443'shows who is listening. - Too many reloads. The Caddy docs warn that reloads abort in-flight certificate requests, so changing and reloading repeatedly can stop issuance from ever completing. Batch your edits.
- The data directory is not persistent. In Docker, mount the data directory as a volume. Without it, Caddy loses its certificates on every container recreation and asks for new ones each time.
While you experiment, use a staging certificate authority. The docs note that production rate limits can block issuance for up to a week, and Let's Encrypt provides a staging endpoint at https://acme-staging-v02.api.letsencrypt.org/directory for exactly this. You can set it with the global acme_ca option in the Caddyfile, then remove it once everything works.
After a failure Caddy retries once, switches challenge types, tries the next issuer, and then backs off, with at most one day between attempts for up to 30 days. That means a fixed DNS or firewall problem may not be picked up instantly. A reload after fixing the cause is the quickest way to trigger a fresh attempt.
Caddy vs Nginx: which should you use#
Caddy wins when you want HTTPS with no moving parts: a handful of apps, a small VPS, and a config you can read in ten seconds. You never have to think about renewal.
Nginx is still the better pick when you rely on its large body of existing tutorials, need modules or tuning Caddy does not cover, or already have a working config you do not want to touch. Neither is faster in a way a small app will notice. If you already run Nginx, there is no need to migrate just for HTTPS; certbot works fine there. For new self-hosted setups, Caddy saves time.
Hardening checklist before you go live#
- Bind your apps to
127.0.0.1so only Caddy is reachable from outside. - Allow only SSH, 80 and 443 in the firewall. Our security hardening guide and SSH key login walkthrough cover the rest.
- Keep Caddy updated through
apt upgrade, and take a snapshot or backup of/etc/caddy/Caddyfileand the data directory before major changes. - Watch the service:
systemctl status caddyand an external uptime check tell you quickly if the proxy is down.
Quick recap#
- Point DNS at the server, open ports 80 and 443, install Caddy from the official repo.
- A site block with a domain and
reverse_proxy host:portis the whole config. - Reload with
sudo systemctl reload caddyand read errors withjournalctl -u caddy. - Use the staging CA while testing, and keep the data directory persistent.
Once the proxy is working, adding another app is a three-line edit and a reload. That is the real benefit of this setup.
Frequently asked questions
How do I set up a Caddy reverse proxy?
Install Caddy, point your domain's A record at the server, open ports 80 and 443, then put the domain and a reverse_proxy line in /etc/caddy/Caddyfile and run sudo systemctl reload caddy. Caddy requests and renews the certificate on its own.
Does Caddy renew HTTPS certificates automatically?
Yes. Caddy renews managed certificates in the background. The data directory that stores them must be writable and persistent, and ports 80 and 443 must stay reachable.
Why is Caddy not getting a certificate?
The usual causes are a DNS record that does not point to the server, ports 80 or 443 blocked by a firewall or the provider, or too many reloads aborting issuance. Check the logs with journalctl -u caddy.
Can Caddy proxy WebSockets?
Yes. reverse_proxy performs the HTTP upgrade and tunnels the connection, with no extra configuration. By default, WebSocket connections are closed when the config reloads.
References
Drafted with AI assistance and checked against LordCloud's published product information. Spotted a mistake?Suggest an edit.



