Caddy: web server with automatic HTTPS in five minutes
Install Caddy, set up a website or reverse proxy with three lines of configuration and get HTTPS without Certbot.
Caddy is a modern web server that handles HTTPS by itself. You write the domain name into the configuration, Caddy fetches the certificate from Let's Encrypt, renews it and redirects HTTP to HTTPS. For small projects and reverse proxies it is the fastest solution.
Install
Caddy has its own repository for Debian and Ubuntu:
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
Caddy then runs as a service. Ports 80 and 443 must be free and open:
sudo ufw allow 80,443/tcp
A static website
The configuration lives in /etc/caddy/Caddyfile. Replace its content:
example.com {
root * /var/www/example.com
file_server
encode gzip zstd
}
sudo mkdir -p /var/www/example.com
echo '<h1>Caddy is running</h1>' | sudo tee /var/www/example.com/index.html
sudo systemctl reload caddy
That's it: https://example.com has a valid certificate and http:// redirects automatically.
Reverse proxy
An application on port 3000 under its own domain:
app.example.com {
reverse_proxy 127.0.0.1:3000
}
Caddy passes headers such as X-Forwarded-For and WebSockets through without further settings.
Several sites
Simply write the blocks one after another:
example.com, www.example.com {
root * /var/www/example.com
file_server
}
app.example.com {
reverse_proxy 127.0.0.1:3000
}
status.example.com {
reverse_proxy 127.0.0.1:3001
}
PHP with Caddy
sudo apt install php-fpm
example.com {
root * /var/www/example.com
php_fastcgi unix//run/php/php8.2-fpm.sock
file_server
}
The version number in the socket name depends on your system; ls /run/php/ shows it. On Ubuntu 24.04 it is 8.3.
Validate, reload, troubleshoot
caddy validate --config /etc/caddy/Caddyfile
sudo systemctl reload caddy
journalctl -u caddy -f
The journal also shows when a certificate could not be issued, for example because the A record is not correct yet.
Caddy, Nginx or Traefik?
| Caddy | Nginx | Traefik | |
|---|---|---|---|
| HTTPS | automatic | with Certbot | automatic |
| Configuration | very short | detailed, very flexible | labels on containers |
| Ideal for | small projects, proxies | large sites, fine-tuning | many Docker apps |
More on the others: Install Nginx and Traefik with Docker.
For the community
Know your stuff? Write a guide.
Share what you know: we review every submitted guide, publish it under your name and say thank you with credit for your services.