GuidesWeb server

Tutorial: install Caddy and get automatic HTTPS

By the Banzai Labs teamUpdated on 2 min read

Before you start

You need a VPS running Ubuntu or Debian, access with sudo, and a domain name.

1. Install Caddy

sudo apt update
sudo apt install caddy
sudo ufw allow 80,443/tcp

The distribution package is enough to start. For the latest version, follow Caddy’s install page.

2. Point the domain

At your registrar, create an A record from the domain to the server’s IP address. Wait until it resolves before going on.

3. Write the configuration

Open /etc/caddy/Caddyfile and replace its content:

example.com {
	root * /var/www/example
	file_server
}

For an application listening on a port, Caddy forwards the requests:

api.example.com {
	reverse_proxy localhost:3000
}

4. Check and reload

caddy validate --config /etc/caddy/Caddyfile
sudo systemctl reload caddy

Open https://example.com. The padlock is there. Caddy requested the certificate and will renew it without you.

If the certificate does not arrive

  • The domain does not point to the server yet.
  • Port 80 or 443 is closed.
  • Another web server already uses those ports.

sudo journalctl -u caddy tells you which of the three.

The full method is in Hosting on a VPS.

Frequently asked questions

Is Caddy free?
Yes, Caddy is open source. The certificates come from Let’s Encrypt, which is free too.
What does HTTPS need to work?
The domain must point to the server address and ports 80 and 443 must be open. Caddy does the rest.
Can it serve several sites?
Yes. Add one block per domain in the same file.

Read next

All guides