What You Will Set Up
By the end of this guide, you will have Caddy running on Ubuntu 24.04, serving your website over HTTPS with a valid certificate, and you will not have touched Certbot, a renewal cron job, or a single OpenSSL command. That is the whole point of Caddy: HTTPS is the default, not an add-on you bolt on afterwards.
Caddy is a modern, open-source web server written in Go. Its killer feature is automatic HTTPS. Give it a domain name, and it obtains a certificate from Let's Encrypt, installs it, serves your site over TLS, and renews the certificate before it expires. All of that happens with a configuration file that is often shorter than a single Nginx server block.
This guide covers the official installation from Caddy's own repository, your first Caddyfile, automatic HTTPS with a real domain, and a reverse proxy setup for an app running on your server. It takes about ten minutes if your domain's DNS is already pointing at the server.
Prerequisites
- An Ubuntu 24.04 (or 22.04) server with sudo access. A minimal VPS works fine.
- A domain name with an A record pointing at your server's public IP. Automatic HTTPS cannot work without this, because Let's Encrypt has to reach your server to verify the domain.
- Ports 80 and 443 open in your firewall and at your cloud provider's security group.
- About ten minutes.
Step 1: Update the Server and Install the Prerequisites
Start by updating the package index and installing the small set of tools needed to add a signed third-party repository.
sudo apt update && sudo apt upgrade -y
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl
The first command brings your package lists and installed software up to date. The second installs curl for downloading files, apt-transport-https so apt can fetch packages over HTTPS, and the Debian keyring packages that apt uses to verify signed repositories.
Step 2: Add Caddy's Official Repository
Caddy is not in Ubuntu's default repositories, so add the official repository hosted on Cloudsmith. First import its GPG signing key, then register the repository, keeping the key in the modern /usr/share/keyrings location instead of the deprecated apt-key method.
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
The first command downloads Caddy's public signing key and converts it into the binary format apt expects. The second adds the repository definition to your sources list. The final apt update refreshes the package index so apt can now see Caddy.
Step 3: Install Caddy
With the repository in place, installation is a single command.
sudo apt install caddy
The package installs the Caddy binary, creates a caddy system user, and registers a systemd service that starts automatically and on every boot. Check that everything is in place.
caddy version
sudo systemctl status caddy
The first command should print something like v2.9.1 (any 2.x version is current). The second should show the service as active (running). If the service is not running, start it with sudo systemctl start caddy and enable it with sudo systemctl enable caddy.
Step 4: Open Ports 80 and 443 in the Firewall
Caddy needs port 80 for the ACME HTTP challenge that proves you own the domain, and port 443 for HTTPS traffic. If you use UFW, Ubuntu's default firewall, allow both.
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw status
If UFW is inactive, the rules are stored but not enforced, so enable it with sudo ufw enable — but only after you have allowed SSH (sudo ufw allow OpenSSH), or you will lock yourself out of the server. If your VPS provider has its own firewall or security group, open 80 and 443 there too.
Step 5: Point Your Domain at the Server
Before writing any configuration, confirm your domain actually resolves to the server. Create an A record at your DNS provider pointing your domain (for example example.com) to the server's public IPv4 address. Then verify it from the server itself.
dig +short example.com
The output should be your server's IP address. DNS changes can take a few minutes to a few hours to propagate. Do not continue to the next step until this command returns the right IP, because Let's Encrypt will fail to issue a certificate for a domain it cannot reach.
Step 6: Write Your First Caddyfile
Caddy's configuration lives in /etc/caddy/Caddyfile. The default file serves a welcome page on port 80. Replace it with a site block for your domain. The example below serves a static site from /var/www/html.
sudo nano /etc/caddy/Caddyfile
Delete the existing content and put in your own site block, replacing example.com with your real domain:
example.com {
root * /var/www/html
file_server
}
That is the entire configuration. The domain name on the first line tells Caddy two things: serve this site, and automatically obtain and manage a TLS certificate for it. The root directive sets the folder to serve files from, and file_server turns on static file serving. There is no separate SSL block, no certificate paths, and no listen directive — Caddy infers all of it.
If you have content to serve, put an index.html in the web root. The default permissions work for Caddy's system user, but if you created the files as your own user, make sure they are readable:
echo '<h1>Hello from Caddy</h1>' | sudo tee /var/www/html/index.html
sudo chown -R caddy:caddy /var/www/html
Step 7: Validate and Reload Caddy
Before reloading, validate the configuration so a typo does not take the server down. Caddy can check the file without applying it.
sudo caddy validate --config /etc/caddy/Caddyfile --adapter caddyfile
sudo systemctl reload caddy
If validation prints Valid configuration, the reload applies the new Caddyfile. On the first reload with a real domain, Caddy contacts Let's Encrypt, completes the HTTP challenge on port 80, and stores the certificate. This usually takes a few seconds.
Step 8: Verify HTTPS in the Browser
Open https://example.com in a browser. You should see your page with a padlock in the address bar, and any plain http:// request should automatically redirect to HTTPS. Confirm the redirect and the certificate from the command line as well.
curl -I http://example.com
curl -v https://example.com 2>&1 | grep -E 'subject|issuer|SSL certificate'
The first command should return a 301 redirect to the HTTPS address. The second shows the certificate details, with the issuer listed as Let's Encrypt. Also check Caddy's logs if anything looks wrong:
sudo journalctl -u caddy --no-pager | tail -n 50
Certificate issuance and renewal events appear here, so this is the first place to look whenever HTTPS misbehaves.
Step 9 (Optional): Reverse Proxy to an App
Most real deployments do not serve static files. They run an app — a Node.js server, a Python API, a Docker container — on a local port, and Caddy sits in front of it. Replace the site block with a one-line reverse proxy:
example.com {
reverse_proxy localhost:3000
}
Run sudo systemctl reload caddy again. Caddy now forwards every request to whatever is listening on port 3000, still with automatic HTTPS. Add headers or compression with one more line each if you need them, but for most apps this block is all there is. To proxy to a different app on a different path, add a second site block for a subdomain, for example api.example.com, and Caddy will fetch a second certificate automatically.
Step 10 (Optional): Serve PHP with php-fpm
If you host a PHP site such as WordPress, Caddy pairs with PHP-FPM through a single directive. Install PHP and PHP-FPM first, then use this site block:
sudo apt install -y php-fpm php-mysql
example.com {
root * /var/www/html
php_fastcgi unix//run/php/php-fpm.sock
file_server
}
The php_fastcgi directive hands PHP files to the FPM socket and rewrites clean URLs for you, while file_server still handles static assets. Reload Caddy and your PHP site works over HTTPS with no extra SSL configuration.
Verify It Worked
Run through this checklist before calling the setup done:
caddy versionprints a 2.x version andsystemctl status caddyshowsactive (running).https://example.comloads with a valid padlock, andhttp://example.comredirects to it.curl -I https://example.comreturns200 OK.sudo journalctl -u caddyshows a certificate issued for your domain and no errors.- Certificates renew automatically about 30 days before expiry, so there is nothing to schedule. You can confirm the renewal timer is healthy by checking that the certificate's expiry date is roughly 90 days out:
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -dates.
Common Issues and Fixes
1. "No certificate" or the site only loads over HTTP
This almost always means the domain is not resolving to the server, or port 80 is blocked. Run dig +short example.com and compare it with your server's IP, then check the firewall with sudo ufw status. Let's Encrypt must reach your server on port 80 to complete its challenge.
2. "Address already in use" when starting Caddy
Another web server, usually Nginx or Apache, is already bound to port 80 or 443. Only one server can own a port. Stop the other server with sudo systemctl stop nginx apache2 and disable it with sudo systemctl disable nginx apache2, or run Caddy as a reverse proxy in front of it instead.
3. Caddyfile fails validation
A misplaced brace or a directive in the wrong block is the usual cause. Run sudo caddy fmt --overwrite /etc/caddy/Caddyfile to auto-format the file — formatting errors become obvious — then validate again with caddy validate.
4. 403 Forbidden on your files
Caddy runs as the caddy system user. If your files belong to another user with restrictive permissions, Caddy cannot read them. Fix ownership with sudo chown -R caddy:caddy /var/www/html or at least make the files world-readable with sudo chmod -R 755 /var/www/html.
5. Too many certificates / rate limit errors
Let's Encrypt allows five duplicate certificates per domain per week. If you have been testing and hit the limit, wait, or test with Caddy's staging endpoint by adding acme_ca https://acme-staging-v02.api.letsencrypt.org/directory inside a global block at the top of the Caddyfile while you experiment.
Conclusion
Caddy turns HTTPS from a weekend project into a three-line configuration file. You installed it from the official repository, pointed a domain at your server, and got a valid, auto-renewing certificate without touching Certbot or a cron job. From here, adding a second site is one more block in the same Caddyfile, and putting an app behind it is a single reverse_proxy line.
If you want a hand with server setup, migrations, or keeping a fleet of Ubuntu servers patched and healthy, XpertBees does exactly that — reach out through xpertbees.in and we will take it from here.



