Serving a small static site with Caddy
This site used to be nginx plus a certbot cron job. Caddy does both in one small config and renews certificates on its own.
example.com {
root * /var/www/site
file_server
encode gzip
}
That is the whole thing: Caddy gets a Let's Encrypt certificate on first start, redirects HTTP to HTTPS and keeps the certificate renewed. Ports 80 and 443 need to be reachable for the HTTP challenge.
Things worth adding
header -Serverif you don't want to advertise the software.handle_errorswith arewrite * /404.htmlfor a proper not-found page; the default is an empty body.caddy validate --config /etc/caddy/Caddyfilebeforesystemctl reload caddy.
Installing from the official apt repository keeps it updated together with the rest of the system.