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:
cat /etc/os-release
Check whether another service is already listening on ports 80 or 443:
sudo ss -lntp | grep -E ':(80|443)\b' || true
Check every active public address record for the hostname:
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:
sudo apt update sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl
Add the official stable signing key:
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:
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:
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:
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:
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:
sudo ufw allow OpenSSH
Allow standard web traffic:
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:
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:
sudo install -d -o root -g root -m 755 /var/www/caddy-demo
Create a simple test page:
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:
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:
sudo cp /etc/caddy/Caddyfile /etc/caddy/Caddyfile.bak
Edit the active file:
sudo nano /etc/caddy/Caddyfile
Use this configuration:
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:
sudo caddy fmt --overwrite /etc/caddy/Caddyfile
Validate again:
sudo caddy validate --config /etc/caddy/Caddyfile
Reload the running systemd service:
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:
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:
curl -I https://your-domain.com
Then test the HTTP endpoint:
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.

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:
https://your-domain.com
Confirm the test page loads and the browser reports a trusted HTTPS connection for the hostname.

Check the exact page content from the terminal:
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:
systemctl is-enabled caddy
Check its listeners:
sudo ss -lntp | grep -E ':(80|443)\b'
Check the service account:
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:
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:
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:
site-two.example.com { root /var/www/site-two file_server }
Format, validate, and reload:
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:
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:
sudo ss -lntp | grep -E ':(80|443)\b'
Check the firewall:
sudo ufw status numbered
Check Caddy's journal:
sudo journalctl -u caddy -n 120 --no-pager
If the site returns 403, inspect path permissions instead of recursively making every file executable:
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:
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:
sudo caddy validate --config /etc/caddy/Caddyfile systemctl is-active caddy systemctl is-enabled caddy
Check network listeners:
sudo ss -lntp | grep -E ':(80|443)\b'
Check both HTTP paths:
curl -I http://your-domain.com curl -I https://your-domain.com
Check the static page content:
curl -fsS https://your-domain.com | grep 'Caddy is serving this site'
Review recent warnings or errors:
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:
sudo caddy validate --config /etc/caddy/Caddyfile.bak
Then restore it and reload:
sudo cp /etc/caddy/Caddyfile.bak /etc/caddy/Caddyfile sudo systemctl reload caddy
Remove only the demo content when it is no longer needed:
sudo rm -rf /var/www/caddy-demo
If you intentionally want to uninstall Caddy completely:
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:
sudo rm -rf /var/lib/caddy
Remove the repository files only if you no longer want the Caddy package source:
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.
