How to Install Caddy Web Server on Ubuntu 24.04

Aybars Altınyay
Aybars Altınyay
Platform Engineer & Technical Writer
BeginnerUpdated Nov 17, 202616 min read~30 minutes total
CaddyUbuntu 24.04Web ServerAutomatic HTTPSStatic WebsiteCaddyfileLinux
Last reviewed:
Tutorial
How to Install Caddy Web Server on Ubuntu 24.04
rafftechnologies.com/learn
On this page

Prerequisites

  • A Raff Linux VM running Ubuntu 24.04, a public domain or subdomain with an A record pointing to the VM, SSH access with a non-root sudo user, and ports 80 and 443 available for Caddy

Serve your site over HTTPS with Caddy on your own Ubuntu 24.04 server.

Tested on 1 vCPU and 2 GB RAM: $8.99 a month

  1. 1Pick a Linux imageUbuntu, Debian and more, with your SSH key added.
  2. 2Choose a sizeFrom $4.99 a month. Resize when your app grows.
  3. 3Connect over SSHYour server is up in about 55 seconds.

Ubuntu, Debian and other Linux distributions with full root and SSH access, up and running in about 55 seconds.

Caddy is a web server that can serve static sites and manage HTTPS automatically when you configure a qualifying public domain. In this tutorial, you will install Caddy on a Raff Linux VM running Ubuntu 24.04, serve a static website from /var/www, point a domain to the server, enable ports 80 and 443, validate the Caddyfile, verify automatic HTTPS, inspect certificate and service state, and safely roll the setup back if needed.

This page focuses on installing Caddy as a web server for a static site. Raff has a separate tutorial for using Caddy as a reverse proxy, so the two workflows do not need to duplicate each other. Caddy's official Ubuntu package installs a systemd service named caddy, and Caddy's automatic HTTPS can obtain and renew publicly trusted certificates for qualifying domain names while redirecting HTTP traffic to HTTPS. See the official Caddy installation documentation and Automatic HTTPS documentation for the upstream behavior used here.

You need Ubuntu 24.04, a domain or subdomain whose active A and/or AAAA records point to the VM, SSH access with sudo privileges, and ports 80 and 443 available for Caddy.

Step 1 — Confirm Ubuntu, DNS, and Existing Web Services

Check the operating system:

Bash
cat /etc/os-release

Check whether another service is already listening on ports 80 or 443:

Bash
sudo ss -lntp | grep -E ':(80|443)\b' || true

Check every active public address record for the hostname:

Bash
dig +short A your-domain.com dig +short AAAA your-domain.com

Replace your-domain.com throughout this tutorial with the real hostname you plan to serve. If an AAAA record exists, make sure it points to this server and that IPv6 traffic can actually reach Caddy. A stale AAAA record can send IPv6 clients and ACME validation to the wrong host.

If Nginx or Apache is already serving production traffic on this VM, do not stop it blindly. Decide whether Caddy will replace it, coexist on different ports, or be deployed on another server before continuing.

Verify: Ubuntu should report 24.04, every active A/AAAA record should resolve to an address that reaches this VM, and you should know whether ports 80 and 443 are already in use.

Step 2 — Install Caddy from the Official Repository

Caddy recommends using its official distribution package on supported production systems. Install the repository prerequisites:

Bash
sudo apt update sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl

Add the official stable signing key:

Bash
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | \ sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg

Add the stable repository:

Bash
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | \ sudo tee /etc/apt/sources.list.d/caddy-stable.list

Make the APT files readable:

Bash
sudo chmod o+r /usr/share/keyrings/caddy-stable-archive-keyring.gpg sudo chmod o+r /etc/apt/sources.list.d/caddy-stable.list

Install Caddy:

Bash
sudo apt update sudo apt install -y caddy

The official Debian/Ubuntu package starts Caddy as a systemd service automatically.

Verify: Run caddy version and systemctl is-active caddy. The version command should return a Caddy v2 release and the service should report active.

Step 3 — Allow SSH, HTTP, and HTTPS Through the Host Firewall

If UFW is already active, inspect the current rules first:

Bash
sudo ufw status numbered

Make sure your actual SSH port is allowed before enabling or changing the firewall. For a standard SSH service on port 22:

Bash
sudo ufw allow OpenSSH

Allow standard web traffic:

Bash
sudo ufw allow 80/tcp sudo ufw allow 443/tcp

If UFW is currently inactive and you intend to enable it, confirm SSH access is allowed first, then enable it:

Bash
sudo ufw enable

For normal public automatic HTTPS, Caddy's documentation expects the server to be externally reachable on ports 80 and 443. Port 80 is also used for automatic HTTP-to-HTTPS redirects.

Verify: sudo ufw status should show your SSH rule plus inbound access for TCP 80 and 443 without removing any rules required by other services.

Step 4 — Create a Read-Only Static Site for the Caddy Service

Caddy's systemd documentation recommends serving static files from locations such as /srv or /var/www rather than user home directories. Create the site directory with root ownership:

Bash
sudo install -d -o root -g root -m 755 /var/www/caddy-demo

Create a simple test page:

Bash
cat <<'EOF' | sudo tee /var/www/caddy-demo/index.html > /dev/null <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Caddy on Ubuntu 24.04</title> </head> <body> <h1>Caddy is serving this site</h1> <p>This page is being served from Ubuntu 24.04.</p> </body> </html> EOF

Set the file to a normal world-readable static-file mode:

Bash
sudo chmod 644 /var/www/caddy-demo/index.html

There is no need to make the entire tree writable by the caddy service account or apply chmod -R 755 to every file. The service only needs read and directory-traversal permission for this static site.

Do not place secrets, private keys, database dumps, .env files, repository metadata, or backup archives inside a public document root. Caddy's file_server can hide selected names as defense in depth, but upstream documentation explicitly notes that hide should not be treated as the security boundary for sensitive files.

Verify: Run namei -l /var/www/caddy-demo/index.html and confirm the caddy service can traverse the directories and read the file through normal directory 755 and file 644 permissions. Also confirm the document root contains only files that are intended to be publicly served.

Step 5 — Back Up and Write the Caddyfile

Back up the packaged configuration before replacing it:

Bash
sudo cp /etc/caddy/Caddyfile /etc/caddy/Caddyfile.bak

Edit the active file:

Bash
sudo nano /etc/caddy/Caddyfile

Use this configuration:

Caddyfile
your-domain.com { root /var/www/caddy-demo encode zstd gzip file_server { hide .git .env } }

The root directive defines the site root and file_server enables static-file serving. encode zstd gzip enables response compression when supported by the client. The hide entries make accidental requests for common repository/secret names return as not found, but sensitive files still belong outside the document root.

Caddy's current documentation allows the simplified root /path syntax; older releases required root * /path, which is why older tutorials may show the wildcard form.

Verify: Save the file and run sudo caddy validate --config /etc/caddy/Caddyfile. It should report a valid configuration before you reload the service.

Step 6 — Format the Caddyfile and Reload Without Downtime

Caddy can format the Caddyfile into its canonical style:

Bash
sudo caddy fmt --overwrite /etc/caddy/Caddyfile

Validate again:

Bash
sudo caddy validate --config /etc/caddy/Caddyfile

Reload the running systemd service:

Bash
sudo systemctl reload caddy

Caddy's official service guidance recommends reloads for configuration changes instead of stopping the service, because a graceful reload avoids unnecessary downtime.

Check recent service logs:

Bash
sudo journalctl -u caddy -n 80 --no-pager

Verify: Configuration validation should succeed, systemctl is-active caddy should return active, and the recent journal should not show a repeating configuration or bind error.

Step 7 — Verify Automatic HTTPS

Test the HTTPS endpoint:

Bash
curl -I https://your-domain.com

Then test the HTTP endpoint:

Bash
curl -I http://your-domain.com

For a qualifying public hostname, Caddy automatically manages a trusted certificate and normally redirects HTTP to HTTPS. Certificate issuance can fail if DNS does not point to this server, ports 80/443 are unreachable, another service owns the ports, or the public CA cannot validate the hostname.

caddy-ubuntu-24-04-01-https-static-site.webp

Verify: The HTTPS request should return a successful HTTP response from your site, while the HTTP request should redirect to the HTTPS URL.

Step 8 — Verify the Browser Certificate and Static Content

Open:

Text
https://your-domain.com

Confirm the test page loads and the browser reports a trusted HTTPS connection for the hostname.

Caddy static website loading over HTTPS on Ubuntu 24.04

Check the exact page content from the terminal:

Bash
curl -fsS https://your-domain.com | grep 'Caddy is serving this site'

Verify: The browser should show the expected hostname over trusted HTTPS, and the terminal command should return the test-page heading.

Step 9 — Confirm Service, Ports, and Caddy Storage State

Confirm Caddy is enabled at boot:

Bash
systemctl is-enabled caddy

Check its listeners:

Bash
sudo ss -lntp | grep -E ':(80|443)\b'

Check the service account:

Bash
systemctl show caddy -p User -p Group

The packaged service runs as the caddy user and stores its application data, including certificate state, under the Caddy service user's data directory in /var/lib/caddy.

Check that the data directory exists without printing private key material:

Bash
sudo test -d /var/lib/caddy/.local/share/caddy && echo 'Caddy data directory present'

Verify: Caddy should be enabled, active, listening on the required web ports, running under the expected service account, and have its data directory present.

Step 10 — Add a Second Static Site Safely

To host another domain on the same Caddy service, first point that domain to the VM and create a separate document root:

Bash
sudo install -d -o root -g root -m 755 /var/www/site-two printf '<h1>Second Caddy site</h1>\n' | \ sudo tee /var/www/site-two/index.html > /dev/null sudo chmod 644 /var/www/site-two/index.html

Add another site block to /etc/caddy/Caddyfile:

Caddyfile
site-two.example.com { root /var/www/site-two file_server }

Format, validate, and reload:

Bash
sudo caddy fmt --overwrite /etc/caddy/Caddyfile sudo caddy validate --config /etc/caddy/Caddyfile sudo systemctl reload caddy

Each qualifying hostname can receive its own automatically managed certificate.

Verify: curl -fsS https://site-two.example.com should return the second site's HTML after DNS and certificate issuance are ready.

Step 11 — Troubleshoot Common Caddy Installation Problems

If certificate issuance fails, check all active DNS address records:

Bash
dig +short A your-domain.com dig +short AAAA your-domain.com

If an AAAA record exists, verify that IPv6 reaches this same Caddy host instead of an old or unrelated server.

Check whether Caddy owns the web ports:

Bash
sudo ss -lntp | grep -E ':(80|443)\b'

Check the firewall:

Bash
sudo ufw status numbered

Check Caddy's journal:

Bash
sudo journalctl -u caddy -n 120 --no-pager

If the site returns 403, inspect path permissions instead of recursively making every file executable:

Bash
namei -l /var/www/caddy-demo/index.html ls -l /var/www/caddy-demo/index.html

A typical static site can use directory mode 755 and regular file mode 644, with root ownership, as long as Caddy can traverse the path and read the files.

If Caddy fails after editing the configuration, validate it before another reload:

Bash
sudo caddy validate --config /etc/caddy/Caddyfile

Verify: Identify whether the failure is DNS, port ownership, firewall, filesystem permission, or Caddyfile syntax before changing unrelated settings.

Step 12 — Run the Final End-to-End Verification

Check configuration and service state:

Bash
sudo caddy validate --config /etc/caddy/Caddyfile systemctl is-active caddy systemctl is-enabled caddy

Check network listeners:

Bash
sudo ss -lntp | grep -E ':(80|443)\b'

Check both HTTP paths:

Bash
curl -I http://your-domain.com curl -I https://your-domain.com

Check the static page content:

Bash
curl -fsS https://your-domain.com | grep 'Caddy is serving this site'

Review recent warnings or errors:

Bash
sudo journalctl -u caddy -p warning --since today --no-pager

Verify: The Caddyfile should validate, the service should be active and enabled, ports 80 and 443 should be served by Caddy, HTTP should redirect to HTTPS, HTTPS should return the static page, and the journal should not show unresolved repeating errors.

Step 13 — Roll Back or Remove the Demo Site

If you want to keep Caddy but restore the original packaged configuration, validate the backup first:

Bash
sudo caddy validate --config /etc/caddy/Caddyfile.bak

Then restore it and reload:

Bash
sudo cp /etc/caddy/Caddyfile.bak /etc/caddy/Caddyfile sudo systemctl reload caddy

Remove only the demo content when it is no longer needed:

Bash
sudo rm -rf /var/www/caddy-demo

If you intentionally want to uninstall Caddy completely:

Bash
sudo systemctl disable --now caddy sudo apt purge -y caddy sudo apt autoremove -y

Before deleting /var/lib/caddy, remember that it contains Caddy-managed application state such as certificate data. Remove it only when you are intentionally decommissioning the service and do not need that state:

Bash
sudo rm -rf /var/lib/caddy

Remove the repository files only if you no longer want the Caddy package source:

Bash
sudo rm -f /etc/apt/sources.list.d/caddy-stable.list sudo rm -f /usr/share/keyrings/caddy-stable-archive-keyring.gpg

Remove firewall rules for 80/443 only if no remaining service on this VM needs them.

Verify: If you restored the previous config, Caddy should remain active with that configuration. After a full uninstall, the Caddy service should no longer be active and your unrelated SSH/firewall access should remain intact.

Conclusion

You now have Caddy installed on Ubuntu 24.04 as a static web server with automatic HTTPS, a systemd-managed service, a validated Caddyfile, safe file permissions, HTTPS verification, multi-site expansion, troubleshooting, and rollback instructions.

Compare current Raff pricing for the Linux VM resources and billing terms that fit your websites; Caddy itself is generally lightweight, but your applications, traffic, storage, and backups determine sizing. If you are choosing a web-server stack, see Caddy Server vs Nginx or VPS for Web Hosting. For a Caddy reverse-proxy setup, follow the dedicated guide linked in the introduction rather than repeating a different deployment workflow here.

Deploy a Raff Ubuntu Linux VM for your Caddy static website with automatic HTTPS. Choose VM resources for the sites and workloads you host, and test DNS, firewall rules, and recovery.

Tested on 1 vCPU and 2 GB RAM: $8.99 a month · 14-day money-back guarantee

Deploy Your Server
Was this article helpful?
Aybars Altınyay
Aybars Altınyay
Platform Engineer & Technical Writer

Aybars is a Platform Engineer & Technical Writer at Raff Technologies. He works on Linux VM templates, self-hosted application workflows, and security-focused deployment validation, turning tested infrastructure procedures into clear, practical tutorials for developers and teams.

Serve your site over HTTPS with Caddy on your own Ubuntu 24.04 server.

Tested on 1 vCPU and 2 GB RAM: $8.99 a month

Ubuntu, Debian and other Linux distributions with full root and SSH access, up and running in about 55 seconds.

14-day money-back guarantee

Frequently asked questions

What is Caddy?
Caddy is an open-source web server with automatic HTTPS built into its normal site configuration. It can serve static files, act as a reverse proxy, and support other HTTP workloads.
Does Caddy automatically configure HTTPS?
For qualifying hostnames, Caddy can automatically obtain and renew publicly trusted certificates and redirect HTTP traffic to HTTPS. DNS and external reachability still need to be configured correctly.
What ports does Caddy need for normal public HTTPS?
For the standard public setup in this tutorial, make TCP ports 80 and 443 externally reachable. Caddy uses 443 for HTTPS and normally uses port 80 for HTTP-to-HTTPS redirects and ACME validation paths when applicable.
Should I use chmod -R 755 on a Caddy website directory?
Usually no. Directories need traversal permission and static files need read permission, but ordinary files do not need executable permission. This tutorial uses directory mode 755 and file mode 644 instead of recursively making every file executable.
Should Caddy own my static website files?
Not necessarily. A static site can remain root-owned as long as the Caddy service can traverse the directories and read the files. Avoid giving the web server write access unless the application actually requires it.
Can Caddy host multiple domains on one VM?
Yes. Add a separate site block for each hostname in the Caddyfile and point each hostname to the VM. Qualifying domains can receive individually managed HTTPS certificates.
Is this tutorial also for Caddy reverse proxy configuration?
No. This page focuses on installing Caddy and serving static files. Raff has a separate Caddy reverse proxy tutorial so reverse-proxy search intent and configuration remain on a dedicated page.
How much does it cost to run Caddy on Raff?
Caddy is free and open source. Hosting costs depend on the Raff Linux VM class and resources you select, plus any optional storage or backup services. Check rafftechnologies.com/pricing for the current monthly plans and billing terms.