Running a small homelab with Nginx as the front‑end for a handful of services, I like to put Caddy in front. It gives me automatic HTTPS, a tidy reverse‑proxy, and the peace of mind that certificates are always fresh. The trick is to keep the renewal process from touching Nginx at all. Below is the practical walk‑through I use every day, with all the commands and details intact.
Why Caddy + Nginx?
Caddy’s built‑in ACME client is a major reason it’s the go‑to for homelabs. It can request, renew, and reload certificates without a manual touch. Nginx, meanwhile, is the workhorse that serves static files, runs PHP‑FPM, or forwards requests to Docker containers. By putting Caddy in front, you get:
- Automatic HTTPS – no manual cert handling.
- Simple reverse‑proxy – Caddy forwards to Nginx on a private port.
- Graceful reloads – Caddy can reload its config without dropping connections.
The only thing you must avoid is making Nginx participate in the TLS handshake; that’s what keeps the renewal zero‑downtime.
1. Baseline architecture
┌─────────────────────┐
│ Public Internet │
│ (DNS A → 192.0.2.1) │
└─────────────┬───────┘
│
▼
┌─────────────────────┐
│ Caddy (port 80/443)│
│ reverse‑proxy to │
│ Nginx (port 8080) │
└─────────────┬───────┘
│
▼
┌─────────────────────┐
│ Nginx (internal) │
│ serves sites │
└─────────────────────┘
- Caddy listens on the public ports 80 and 443.
- Nginx is bound to a local port (e.g., 8080) and is not exposed directly to the Internet.
- DNS points to the server’s public IP.
2. Install Caddy and Nginx
On a Debian‑based system (Ubuntu 24.04, Debian 12), the easiest way is to use the official Caddy APT repository:
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
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 -y caddy
Nginx is already in the default repos:
sudo apt install -y nginx
3. Configure Caddy
Create a simple Caddyfile in /etc/caddy/Caddyfile:
{
# Global options
email [email protected]
acme_ca https://acme-v02.api.letsencrypt.org/directory
# Use the default ACME challenge on port 80
}
example.com {
reverse_proxy localhost:8080
}
emailis required for Let’s Encrypt.- The
acme_caline is optional; it points to the production CA. reverse_proxyforwards all traffic to Nginx.
Restart Caddy to apply the config:
sudo systemctl restart caddy
Caddy will automatically request a certificate for example.com. Verify it:
sudo caddy certificates
4. Nginx behind Caddy
Because Caddy is the entry point, Nginx should only listen on the private port. Edit /etc/nginx/sites-available/default (or create a new file):
server {
listen 8080;
server_name example.com;
root /var/www/html;
index index.html index.htm;
# Forward the X-Forwarded-For header so logs show real client IP
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
location / {
try_files $uri $uri/ =404;
}
}
Reload Nginx:
sudo systemctl reload nginx
Now Caddy receives HTTPS, decrypts it, and forwards the plain HTTP request to Nginx. No certificate handling is done by Nginx.
5. Let’s Encrypt renewal logic
Caddy’s ACME client renews certificates automatically 30 days before expiry. By default, it reloads its own configuration after a successful renewal. Because Nginx is not involved in the TLS handshake, there is no risk of a certificate mismatch.
5.1 Verify renewal schedule
Caddy logs renewal events. Check the log:
journalctl -u caddy -f
You should see entries like:
2026-11-15T12:34:56+00:00 INFO caddy.acme: Renewed certificate for example.com
If you want to force a renewal for testing:
sudo caddy renew --force
Caddy will fetch a fresh cert and reload itself. Nginx stays untouched.
6. Avoiding Nginx downtime
The only time Nginx could go down is if you manually restart it. The renewal workflow keeps it running. However, there are a few edge cases to consider:
| Situation | What happens | Mitigation |
|---|---|---|
| Caddy crashes | Connections drop until Caddy restarts | Use systemd Restart=always (default) |
| Nginx misconfiguration | Caddy still forwards, but 502 errors | Keep Nginx config in sync; test with nginx -t before reload |
| DNS change | Caddy may need to re‑request cert | Update Caddyfile and reload Caddy |
Because Caddy is the only service that touches TLS, you can safely ignore Nginx in the renewal process.
7. Practical example: adding a new sub‑domain
Suppose you want blog.example.com to point to a different Nginx block. Add it to the Caddyfile:
blog.example.com {
reverse_proxy localhost:8081
}
Create a new Nginx site on port 8081:
sudo tee /etc/nginx/sites-available/blog <<'EOF'
server {
listen 8081;
server_name blog.example.com;
root /var/www/blog;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
EOF
sudo ln -s /etc/nginx/sites-available/blog /etc/nginx/sites-enabled/
sudo systemctl reload nginx
Caddy will automatically request a certificate for blog.example.com and reload itself. No manual intervention is needed.
8. Troubleshooting common issues
8.1 Caddy cannot reach Let’s Encrypt
Check network connectivity:
curl https://acme-v02.api.letsencrypt.org/directory
If the request times out, ensure outbound HTTPS (port 443) is allowed. In a typical homelab, this is not a problem unless a firewall blocks it.
8.2 Nginx returns 502 Bad Gateway
This usually means the reverse‑proxy target is unreachable. Verify the port:
sudo ss -tlnp | grep 8080
If nothing is listening, restart Nginx:
sudo systemctl restart nginx
8.3 Caddy logs “certificate not found”
If you added a new domain but Caddy didn’t request a cert, check the Caddyfile syntax. A missing } or stray character can prevent the block from being parsed.
sudo caddy validate
The command will point out syntax errors.
8.4 Certificate renewal fails repeatedly
Look at the ACME challenge logs:
journalctl -u caddy -o short | grep -i challenge
Common causes:
- HTTP challenge blocked – Caddy must be able to serve
/.well-known/acme-challenge/*on port 80. Ensure no firewall or Nginx rule blocks it. - DNS propagation delay – If you just added a DNS record, wait a few minutes.
9. Security considerations
- Keep Caddy updated – The ACME protocol and TLS libraries are updated frequently. Use
apt upgrade caddyregularly. - Use the
emaildirective – Let’s Encrypt will send expiry notices to this address. - Restrict Nginx to localhost – Binding Nginx to
127.0.0.1:8080(instead of0.0.0.0) prevents external access if Caddy fails. - Enable HTTP/2 – Caddy defaults to HTTP/2, which is more efficient and secure. Nginx can also be configured for HTTP/2 if you expose it internally.
10. Automating everything with systemd timers
If you prefer to control renewal timing yourself, you can replace Caddy’s built‑in scheduler with a systemd timer that runs caddy renew --force every 10 days. Create /etc/systemd/system/caddy-renew.timer:
[Unit]
Description=Force Caddy certificate renewal every 10 days
[Timer]
OnCalendar=*-*-* 00:00:00
Persistent=true
RandomizedDelaySec=1h
[Install]
WantedBy=timers.target
Create the service /etc/systemd/system/caddy-renew.service:
[Unit]
Description=Force Caddy renewal
After=caddy.service
[Service]
Type=oneshot
ExecStart=/usr/bin/caddy renew --force
Enable and start:
sudo systemctl enable --now caddy-renew.timer
This approach gives you deterministic renewal intervals while still keeping Nginx untouched.
11. Summary of trade‑offs
| Approach | Pros | Cons |
|---|---|---|
| Caddy’s built‑in ACME | Zero configuration, automatic reloads, no downtime | Slightly more memory than a bare Nginx setup |
| Manual cert handling + Nginx reload | Full control over cert files | Risk of mis‑reload, potential downtime |
Systemd timer + caddy renew --force |
Predictable schedule | Requires extra timer files |
For most homelab users, the default Caddy ACME flow is the simplest and safest. The timer method is useful if you want to audit renewals or integrate with other scripts.
12. Final checklist
- Caddy: installed,
Caddyfilepointing to Nginx,systemctl status caddyis active. - Nginx: listening on a private port, config tested (
nginx -t), reloaded (systemctl reload nginx). - DNS: A record for
example.compoints to your server’s public IP. - Firewall: Allow ports 80 and 443 outbound to Let’s Encrypt.
- Logs:
journalctl -u caddyshows successful renewal messages. - Backup: Keep a copy of your
Caddyfileand Nginx configs in a versioned repo.
With these steps, your homelab will enjoy uninterrupted HTTPS service, and you can focus on building more sites instead of chasing certificate expirations.
See also
- How to Run a Home‑Lab MQTT Broker with Traefik and ACME on Debian
- Running a Home NAS with TrueNAS CORE: From ZFS Pool to SMB Shares
- Quickly Restore a Mistakenly Deleted Home Folder with Btrfs Snapshots
- Deploy Traefik to Route Home NAS and Pi‑Hole Without Self‑Signed Certs
- Using jq to extract a single field from nested JSON logs