If you run several services in your homelab – Nextcloud, Home Assistant, Paperless, a WordPress blog – you want to reach them under their own domain names and with valid HTTPS. The classic approach: Nginx or Apache as a reverse proxy, plus certbot, cron jobs and long configuration files. Caddy makes this much simpler: a web server in a single file that obtains and renews Let’s Encrypt certificates on its own. A complete proxy configuration is often just three lines long.
This blog runs behind Caddy, too. In this article I show how to set up Caddy on Debian or Ubuntu and cover typical homelab scenarios.
What is a reverse proxy?
A reverse proxy accepts all requests on ports 80 and 443 and forwards them to the right service on your network based on the domain name. From the outside you only see one server with a valid certificate; behind it there can be any number of containers, VMs or devices that only speak plain HTTP themselves. On the router you only need to forward ports 80 and 443 to the proxy – no longer one rule per service.
Installing Caddy
Debian and Ubuntu do ship Caddy in their own repositories, but the version there is often considerably outdated. The official repository of the Caddy developers is the better choice:
sudo apt install -y 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 apt update
sudo apt install caddy
The package sets up a systemd service that runs as its own user caddy and starts immediately. If you now open the server’s IP address in a browser, the Caddy welcome page appears. The configuration lives in /etc/caddy/Caddyfile.
If Apache or Nginx is already listening on port 80/443 on the machine, Caddy will not start. In that case stop the other web server first or move it to different ports.
Your first proxy: three lines
Suppose Nextcloud runs on 192.168.1.20, port 8080, and should be reachable at cloud.example.org. The DNS record points to your public IP, and the router forwards 80 and 443 to the Caddy server. Then this is all the Caddyfile needs:
cloud.example.org {
reverse_proxy 192.168.1.20:8080
}
sudo systemctl reload caddy
That’s it. Caddy recognises from the domain name that HTTPS is wanted, requests a certificate from Let’s Encrypt (or ZeroSSL as a fallback), redirects HTTP to HTTPS automatically and renews the certificate well before it expires. No certbot, no cron job, no paths to fullchain.pem. WebSockets and HTTP/2 or HTTP/3 work without any further effort.
Additional services are simply additional blocks:
{
email admin@example.org
}
cloud.example.org {
reverse_proxy 192.168.1.20:8080
}
blog.example.org {
reverse_proxy 192.168.1.30:8086
}
www.blog.example.org {
redir https://blog.example.org{uri} permanent
}
The unnamed block at the very top holds global options. The e-mail address is optional, but it is passed on to the certificate authority and helps if there are problems with the account.
Checking and reloading the configuration
caddy fmt --overwrite /etc/caddy/Caddyfile # normalise indentation
caddy validate --config /etc/caddy/Caddyfile # check the syntax
sudo systemctl reload caddy # apply without interruption
journalctl -u caddy -f # follow the log live
A reload does not interrupt any open connections. If the new configuration is faulty, Caddy simply keeps the old one – so the website stays online. Make a copy before larger changes anyway: sudo cp /etc/caddy/Caddyfile /etc/caddy/Caddyfile.bak.
Passing the real visitor IP to the service
Behind a proxy, the actual service initially only sees Caddy’s IP address. Caddy therefore sets the headers X-Forwarded-For, X-Forwarded-Proto and X-Forwarded-Host automatically. Some applications expect X-Real-IP instead – you can send that along as well:
blog.example.org {
reverse_proxy 192.168.1.30:8086 {
header_up X-Real-IP {remote_host}
}
}
Important: the service behind the proxy must only trust these headers when they come from the proxy’s IP. With Apache this is handled by mod_remoteip with RemoteIPHeader X-Real-IP and RemoteIPInternalProxy, with Nextcloud by the trusted_proxies setting in config.php. You should also tell the application that it is reachable via HTTPS – otherwise WordPress, for example, generates links with http:// or ends up in a redirect loop.
Backends with their own HTTPS (Proxmox, UniFi & co.)
Some web interfaces only speak HTTPS with a self-signed certificate, for instance Proxmox VE on port 8006. Caddy would refuse the connection because of the invalid certificate. On the internal network you can switch off verification for this one backend:
pve.example.org {
reverse_proxy https://192.168.1.5:8006 {
transport http {
tls_insecure_skip_verify
}
}
}
Visitors still get a valid certificate. However, you should really only do this for connections inside your own LAN.
Internal services: certificates via DNS challenge
By default, Let’s Encrypt verifies via port 80 or 443 that the domain belongs to you. For services that should not be reachable from the internet at all – Proxmox, the router, Home Assistant – you do not want to open any ports, though. The solution is the DNS challenge: as proof, Caddy creates a TXT record at your DNS provider. This also makes wildcard certificates such as *.home.example.org possible.
For this, Caddy needs a module for the DNS provider in question. These modules are not part of the standard package; you have to use a customised Caddy binary. The easiest way is:
sudo caddy add-package github.com/caddy-dns/cloudflare
sudo systemctl restart caddy
caddy list-modules | grep dns.providers
add-package downloads a freshly built Caddy binary and replaces the installed one. The catch: on the next apt upgrade the package overwrites the file with the standard version again – and Caddy no longer starts because the module is missing. The remedy: put Caddy on hold with sudo apt-mark hold caddy and install updates with sudo caddy upgrade (which keeps the modules), or build the binary yourself with xcaddy, or use a suitable Docker image.
At Cloudflare, create a token under My Profile → API Tokens with the permission Zone → DNS → Edit for your own zone. The token does not belong in the Caddyfile but in the service’s environment:
sudo systemctl edit caddy
[Service]
Environment=CF_API_TOKEN=put-your-token-here
In the Caddyfile the token is then referenced through an environment variable. A wildcard block with several internal services looks like this:
*.home.example.org {
tls {
dns cloudflare {env.CF_API_TOKEN}
}
@pve host pve.home.example.org
handle @pve {
reverse_proxy https://192.168.1.5:8006 {
transport http {
tls_insecure_skip_verify
}
}
}
@ha host ha.home.example.org
handle @ha {
reverse_proxy 192.168.1.40:8123
}
handle {
abort
}
}
The DNS records for *.home.example.org then point to the internal IP of the Caddy server – either at Cloudflare itself or on your own DNS server (Pi-hole, AdGuard Home, router). Unknown subdomains are dropped without a response by the last handle block. A nice side effect: only the wildcard name shows up in the public certificate logs (Certificate Transparency), not every single service.
Pitfall: caddy validate in the shell now reports an error because the variable CF_API_TOKEN is not set there – it only exists in the environment of the systemd service. The Caddyfile is fine nevertheless; if in doubt, just run systemctl reload caddy and check with journalctl -u caddy.
Bundling recurring settings in snippets
If you need the same settings in many blocks, define a snippet in parentheses and include it with import:
(security) {
header {
Strict-Transport-Security "max-age=31536000"
X-Content-Type-Options "nosniff"
Referrer-Policy "strict-origin-when-cross-origin"
-Server
}
}
blog.example.org {
import security
reverse_proxy 192.168.1.30:8086
}
Password protection for simple services
Some web interfaces have no login of their own. Caddy can protect them with HTTP basic auth. First generate a password hash:
caddy hash-password
status.example.org {
basic_auth {
admin $2a$14$...your-hash-here...
}
reverse_proxy 192.168.1.50:3001
}
Older guides still spell the directive basicauth – since Caddy 2.8 it is called basic_auth.
Logs and privacy
Unlike Apache or Nginx, Caddy writes no access log out of the box. Only start-up, certificate operations and errors end up in the journal. For a private website that is pleasant: no IP addresses on disk, no log rotation needed. If you do need an access log, for example for Fail2ban, enable it per site:
blog.example.org {
log {
output file /var/log/caddy/blog.log {
roll_keep_for 168h
}
}
reverse_proxy 192.168.1.30:8086
}
With roll_keep_for, old log files are deleted automatically after seven days.
When to use Caddy – and when not
- Caddy fits if you like a readable text file, want automatic HTTPS and like to back up and version your configuration.
- Nginx Proxy Manager offers a graphical interface – handy for beginners, but less flexible and harder to back up.
- Traefik shows its strengths when many Docker containers come and go and should configure themselves via labels.
- Nginx or Apache with certbot still make sense if you already work with them or need special modules. How to do it with Apache is covered in the article Apache: free SSL certificate with Let’s Encrypt and certbot.
For a typical homelab with a handful of services, Caddy is the most convenient choice in my opinion: once set up, you never have to think about certificates again.