Setting up a web server often involves a tedious dance: install Nginx or Apache, configure virtual hosts, install Certbot, generate Let's Encrypt certificates, and set up cron jobs for renewal.
Caddy changes the game completely. It is a modern, open-source web server written in Go that handles HTTPS automatically and by default.
Why Use Caddy?
- Automatic HTTPS: Caddy automatically obtains and renews TLS certificates for your sites (via Let's Encrypt or ZeroSSL). No extra steps required.
- Simple Configuration: The
Caddyfilesyntax is incredibly human-readable compared to Nginx or Apache configs. - Production Ready: It supports HTTP/3, compression, and robust reverse proxying out of the box.
Prerequisites
- A Linux server (Ubuntu/Debian used in examples).
- Root or sudo access (required for installation and binding to ports 80/443).
- A domain name (e.g.,
example.com) pointing to your server's IP address.
Step 1: Install Caddy
These commands work for Debian, Ubuntu, and Raspbian. For other distributions, check the official docs.
First, install the necessary dependencies and add the official Caddy repository key:
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.listNow, update your package list and install Caddy:
sudo apt update
sudo apt install caddyOnce installed, Caddy starts automatically as a systemd service. You can check its status:
systemctl status caddyStep 2: Configure Caddy
Caddy is configured using a file located at /etc/caddy/Caddyfile.
Open it with your favorite editor (requires sudo):
sudo nano /etc/caddy/CaddyfileExample A: Reverse Proxy (Node.js, Python, Go)
This is the most common use case. If you have an app running on localhost:3000, your Caddyfile should look like this:
example.com {
reverse_proxy localhost:3000
}That is literally it. Caddy will see the domain name, automatically fetch an SSL certificate, and proxy traffic to port 3000.
Example B: Static File Server
If you just want to serve HTML/CSS/JS files from a directory:
example.com {
root * /var/www/html
file_server
encode gzip
}Step 3: Reload and Test
After saving your Caddyfile, apply the changes without downtime:
sudo systemctl reload caddyVerification
- Open your browser and visit
https://example.com. - You should see the lock icon indicating a secure connection.
- You didn't have to run Certbot or manage keys manually!
Troubleshooting
If something isn't working, check the logs:
journalctl -u caddy --no-pager | tail -n 20Or validate your configuration file for errors before reloading:
caddy validate --config /etc/caddy/CaddyfileConclusion
Caddy removes the friction of managing web servers and security certificates. For most modern deployments, especially on simple VPS instances, it is the most efficient choice.