Caddy on Linux: run it as a service, validate changes and keep automatic HTTPS working
Caddy obtains and renews certificates by itself, which is why it fails in a quiet way when something blocks that: a closed port 80, a DNS record that points elsewhere, or a data folder that is not writable. This guide sets it up so changes are checked first and renewals keep working.
Install from the official package repository
Use the Caddy repository so the service unit, the caddy user and updates come from the package manager. Follow the current instructions for your distribution on the Caddy site.
sudo systemctl status caddy --no-pager caddy versionKeep the Caddyfile in one place
The packaged service reads /etc/caddy/Caddyfile. A site block with just the domain is enough to get HTTPS.
# /etc/caddy/Caddyfile example.com { root * /var/www/example file_server }Validate before you apply
caddy validate parses the file and reports mistakes without touching the running server. Reload applies the new config gracefully with no dropped connections.
caddy validate --config /etc/caddy/Caddyfile --adapter caddyfile sudo systemctl reload caddyOpen ports 80 and 443 and check DNS
The ACME challenge needs the domain to resolve to this server and port 80 or 443 to be reachable. If a firewall or a proxy blocks both, issuance fails and the old certificate expires.
sudo ufw allow 80,443/tcp dig +short example.comMake sure the data folder is persistent and writable
Certificates and account keys live in the caddy home, normally /var/lib/caddy. If it is lost on every restart (a container without a volume), Caddy asks for new certificates each time and hits rate limits.
sudo ls -la /var/lib/caddy/.local/share/caddy/certificates 2>/dev/nullRead the logs when something is wrong
The journal shows issuance and renewal attempts and the reason for a failure.
sudo journalctl -u caddy --since '1 hour ago' --no-pager | tail -n 50
Common mistakes
- Editing the Caddyfile and restarting instead of validating first: a typo takes every site down.
- Running Caddy in a container without a volume for its data folder.
- Putting a CDN proxy in front with a mode that blocks the challenge, then forgetting why renewals fail.
How to undo it
Restore the previous Caddyfile from your backup or git history, run caddy validate, then sudo systemctl reload caddy. Certificates already issued are kept in the data folder.
Sources
Commands are for Debian and Ubuntu unless noted. Test on a copy first and keep a backup: you are responsible for changes on your own systems.