How To Install Caddy on Ubuntu 26.04 LTS

Install Caddy on Ubuntu 26.04

Most people who set up a web server on a fresh VPS lose an hour or two to the same routine. They install Nginx, write a server block, run Certbot, fix the renewal timer, and then discover that the HTTP to HTTPS redirect loops. Then they repeat it all for the second domain. It works, but it is a lot of ceremony for something that should be boring.

Caddy removes most of that ceremony. It obtains and renews TLS certificates by itself, redirects HTTP to HTTPS without being asked, and speaks HTTP/2 and HTTP/3 out of the box. A working reverse proxy with a valid certificate can be three lines of config. After years of babysitting certificate cron jobs on production boxes, that simplicity is a real operational advantage, not a gimmick.

Ubuntu 26.04 LTS “Resolute Raccoon” shipped on 23 April 2026 with kernel 7.0 and standard security maintenance running to 2031 [10]. That makes it a sensible base for anything you want to leave running for years. This guide covers the whole path on that release: choosing an install method, installing from the official repository, writing a Caddyfile, running a reverse proxy, locking the server down, tuning it, and fixing the errors that actually show up in practice.

Why Caddy Instead of Nginx or Apache?

The honest answer is that it depends on what you value. Nginx still wins on raw ecosystem depth and a mountain of tutorials. Apache is unbeatable if you rely on .htaccess and legacy modules. Caddy wins on operational simplicity and safe defaults.

A few things stand out in real deployments:

  • Automatic HTTPS. Caddy provisions certificates from Let’s Encrypt or ZeroSSL for any public domain in your config, and renews them before expiry.
  • Sane TLS defaults. Modern protocol versions and cipher suites are chosen for you, so there is no copy-pasted SSL block from 2017.
  • HTTP/3 support. QUIC is available without compiling anything.
  • One static binary. There are no dependency chains and upgrades are predictable.
  • A readable config. The Caddyfile is short enough that a teammate can review it in seconds.

Where Caddy is a weaker fit: very exotic Nginx-specific modules, or teams with large existing Nginx configuration libraries that would cost more to migrate than they save.

Choosing an Install Method

There are several ways to get Caddy onto Ubuntu 26.04. They are not equal.

Method Best for Trade-off
Official Caddy APT repository Most production servers Adds a third-party repo, but gives current stable builds and normal apt upgrade updates
Ubuntu’s own package Quick tests Can lag well behind upstream releases
Static binary download Containers, custom builds You manage the service file and updates yourself
xcaddy custom build Needing plugins such as DNS challenge providers You must rebuild on every update
Docker image Container-based stacks Adds volume and networking considerations

For a typical VPS, the official repository is the right call. The Caddy documentation lists it as the supported route for Debian and Ubuntu, and the package installs and starts Caddy as a systemd service named caddy [1]. The rest of this guide uses it. At the time of writing, the latest upstream release is 2.11.9, published on 5 November 2026 [2].

Prerequisites Before You Touch the Server

Spending five minutes here prevents most of the troubleshooting section later.

  1. A fresh or well-understood Ubuntu 26.04 LTS server with a non-root sudo user.
  2. A domain name with an A record (and AAAA if you use IPv6) pointing at the server’s public IP.
  3. Ports 80 and 443 reachable from the internet. Port 80 is needed for the HTTP challenge and 443 for TLS. UDP 443 is needed for HTTP/3.
  4. Nothing else listening on those ports. A leftover Apache or Nginx install is the number one cause of a failed first start.

Check the release and what is already using the ports:

lsb_release -a
sudo ss -tulpn | grep -E ':(80|443)\b'

If ss prints anything, stop and deal with it first. To remove a leftover web server:

sudo systemctl disable --now nginx apache2 2>/dev/null

Then bring the system up to date:

sudo apt update && sudo apt upgrade -y

A reboot is worth doing if a new kernel came in. It is much nicer to find out that the server does not come back cleanly now than at 2 a.m. later.

Step 1: Install Caddy from the Official Repository

Install the helper packages first. They provide the keyrings and transport support that the repository setup needs:

sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl gnupg

Import the signing key into a dedicated keyring file. Using a dedicated keyring, not the legacy global trust store, is the modern practice. It means the key can only vouch for this one repository:

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 repository definition and make both files readable:

curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo chmod o+r /usr/share/keyrings/caddy-stable-archive-keyring.gpg
sudo chmod o+r /etc/apt/sources.list.d/caddy-stable.list

Those commands follow the official documentation [1]. The chmod lines look trivial, but skipping them can produce confusing “permission denied” or signature errors when apt runs as the unprivileged _apt user.

Now install:

sudo apt update
sudo apt install -y caddy

Confirm what you got and where it came from:

caddy version
apt policy caddy

apt policy should show the Cloudsmith repository as the candidate source. If it shows an Ubuntu archive version instead, the repo line was not picked up and you should recheck the file in /etc/apt/sources.list.d/.

A side note on Ubuntu 26.04 specifically: if apt complains about the .list format or you prefer the newer deb822 .sources style, you can convert the entry. Both formats work. The one-line .list approach is what the vendor documents, so it remains the safest to copy.

Step 2: Understand What the Package Installed

Knowing the layout saves you from hunting later.

  • Binary: /usr/bin/caddy
  • Main config: /etc/caddy/Caddyfile
  • Service unit: /lib/systemd/system/caddy.service (and /usr/lib/systemd/system/ on merged-usr systems)
  • Runs as: user and group caddy
  • Data and certificates: /var/lib/caddy/.local/share/caddy
  • Logs: the systemd journal by default

Check that the service came up:

sudo systemctl status caddy

You should see active (running). The package also enables it at boot. If you ever see the unit marked failed, jump to the troubleshooting section.

The default Caddyfile serves a placeholder page on port 80. Open http://YOUR_SERVER_IP and you should see the Caddy welcome page. That alone proves the package, the service and the firewall path all work.

Step 3: Open the Firewall Properly

Ubuntu ships with UFW, which is disabled by default. Enable it carefully. Locking yourself out of SSH on a remote machine is a rite of passage nobody needs to repeat.

sudo ufw allow OpenSSH
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw allow 443/udp
sudo ufw enable
sudo ufw status verbose

The 443/udp rule is the one people forget. Without it, browsers quietly fall back to HTTP/2 over TCP. Nothing breaks, so nobody notices that HTTP/3 never kicks in.

If your provider has a cloud firewall or security group (most do), open the same ports there too. A very common story: UFW is perfect, but the VPS panel blocks 443, and certificate issuance fails with timeouts.

Step 4: Write Your First Real Caddyfile

Back up the default, then replace it:

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

Here is a static site example:

example.com, www.example.com {
    root * /var/www/example.com/public
    encode zstd gzip
    file_server

    header {
        Strict-Transport-Security "max-age=31536000; includeSubDomains"
        X-Content-Type-Options "nosniff"
        Referrer-Policy "strict-origin-when-cross-origin"
        -Server
    }

    log {
        output file /var/log/caddy/example.com.access.log
        format json
    }
}

Create the web root and the log directory with correct ownership:

sudo mkdir -p /var/www/example.com/public /var/log/caddy
echo '<h1>It works</h1>' | sudo tee /var/www/example.com/public/index.html
sudo chown -R caddy:caddy /var/log/caddy
sudo chown -R www-data:www-data /var/www/example.com
sudo chmod -R 755 /var/www/example.com

The caddy user needs read access to the web root. World-readable files (mode 644 for files and 755 for directories) are fine. Do not make site content writable by the Caddy user unless something specifically needs it.

Validate before you apply anything. This habit alone prevents most self-inflicted outages:

caddy validate --config /etc/caddy/Caddyfile --adapter caddyfile
sudo caddy fmt --overwrite /etc/caddy/Caddyfile

Then reload without dropping connections:

sudo systemctl reload caddy

reload applies the new config gracefully through Caddy’s admin API. restart kills active connections. On a busy production box, use reload by default.

Within a few seconds Caddy contacts the certificate authority, completes the challenge, and your site loads over HTTPS. Watch it happen:

sudo journalctl -u caddy -f

You will see the ACME order, the challenge, and the certificate being obtained. It is oddly satisfying the first time.

Step 5: Configure Caddy as a Reverse Proxy

This is where most real-world installs end up. A Node.js, Python, Go or PHP-FPM app listens on a local port, and Caddy handles TLS and public traffic.

A simple proxy to an app on port 3000:

app.example.com {
    encode zstd gzip
    reverse_proxy 127.0.0.1:3000
}

That is the entire config for a TLS-terminated proxy. Caddy sets the usual forwarding headers (X-Forwarded-For, X-Forwarded-Proto, X-Forwarded-Host) for you. Make sure your application is configured to trust them, otherwise it will log the proxy’s IP for every visitor.

Load balancing across several backends

api.example.com {
    reverse_proxy 10.0.0.11:8080 10.0.0.12:8080 10.0.0.13:8080 {
        lb_policy least_conn
        health_uri /healthz
        health_interval 10s
        health_timeout 3s
        fail_duration 30s
    }
}

Active health checks mean a crashed backend is pulled out of rotation without anyone paging you. During a traffic spike, least_conn usually behaves better than round robin when request durations vary widely.

PHP applications with PHP-FPM

blog.example.com {
    root * /var/www/blog
    encode zstd gzip
    php_fastcgi unix//run/php/php-fpm.sock
    file_server
}

Check the actual socket path for your PHP version with ls /run/php/. On Ubuntu it is typically versioned, for example php8.4-fpm.sock. Use the real name, because the generic path only exists if you created a symlink.

Redirecting www to the bare domain

www.example.com {
    redir https://example.com{uri} permanent
}

example.com {
    reverse_proxy 127.0.0.1:3000
}

For SEO, pick one canonical hostname and redirect the other. Splitting link equity between www and non-www is a classic and avoidable mistake.

Step 6: Security Hardening That Actually Matters

Caddy’s defaults are strong, but the server around it still needs attention.

Keep the system patched

sudo apt install -y unattended-upgrades
sudo dpkg-reconfigure --priority=low unattended-upgrades

Because Caddy comes from an APT repository, security updates arrive through the same channel as everything else. Check with apt list --upgradable | grep caddy from time to time. Remember that a package upgrade restarts the service, so a long-lived WebSocket connection will drop.

Lock down SSH

sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication no/' /etc/ssh/sshd_config
sudo sed -i 's/^#\?PermitRootLogin.*/PermitRootLogin no/' /etc/ssh/sshd_config
sudo sshd -t && sudo systemctl reload ssh

Test from a second terminal before closing your current session. Always.

Add Fail2ban for noisy bots

sudo apt install -y fail2ban
sudo systemctl enable --now fail2ban

With JSON access logs enabled, you can write a custom filter that bans IPs hammering login endpoints. Do that only if you actually see abuse, because over-engineered ban rules cause their own incidents.

Security headers

The sample Caddyfile above already sets HSTS and nosniff. Add a Content-Security-Policy deliberately and slowly, since a too-strict policy breaks scripts and fonts. Start with Content-Security-Policy-Report-Only and watch the reports before enforcing.

A caution about HSTS: once browsers cache it, you cannot easily go back to plain HTTP for that domain. Start with a short max-age on new domains and increase it after you trust the setup.

Restrict admin access

Caddy’s admin API listens on localhost:2019 by default. Leave it there. Never expose it publicly. If you do not use runtime config changes at all, you can disable it with admin off in the global options block, but note that systemctl reload relies on that API, so disabling it changes how you apply config.

Basic auth for staging sites

Generate a hash:

caddy hash-password

Then use it:

staging.example.com {
    basic_auth {
        deploy $2a$14$REPLACE_WITH_YOUR_GENERATED_HASH
    }
    reverse_proxy 127.0.0.1:4000
}

Staging sites that get indexed by search engines are a quiet SEO problem. Basic auth, or an X-Robots-Tag: noindex header, avoids duplicate content issues.

Troubleshooting Common Caddy Errors

Service fails to start: “address already in use”

Another process holds port 80 or 443.

sudo ss -tulpn | grep -E ':(80|443)\b'
sudo systemctl disable --now nginx apache2
sudo systemctl restart caddy

Certificate not issued or ACME challenge failed

Walk the list in order:

  1. Does the domain’s A or AAAA record point to this server? Check with dig +short example.com.
  2. Are ports 80 and 443 open in both UFW and any cloud firewall?
  3. Is a stale AAAA record sending validation over IPv6 to the wrong machine? This catches people constantly.
  4. Is a CDN proxy (for example an orange-cloud setting) intercepting the challenge? Switch to DNS-only temporarily or use the DNS challenge.
  5. Are you hitting rate limits from repeated failed attempts? Wait, and fix the cause before retrying.

Read the real error:

sudo journalctl -u caddy --no-pager | grep -i -E 'error|acme|tls' | tail -n 40

“permission denied” reading files or writing logs

sudo -u caddy ls -la /var/www/example.com/public
sudo chown -R caddy:caddy /var/log/caddy

Remember that every parent directory needs the execute bit for the caddy user. A locked-down home directory in the path is a classic cause.

Caddyfile syntax errors

Run caddy validate. Common culprits are a missing brace, tab and space inconsistencies, and a directive placed outside any site block. Running caddy fmt often exposes structural mistakes visually.

502 Bad Gateway

Caddy reached for the upstream and got nothing. Check that the app is actually running and listening where you said:

curl -v http://127.0.0.1:3000
sudo ss -tulpn | grep 3000

If the app binds only to a different interface or Unix socket, adjust either side. For PHP-FPM, confirm the socket path and that the caddy user can access it.

Too many redirects

Usually the application is also redirecting to HTTPS because it does not see the forwarded protocol. Configure the app to trust X-Forwarded-Proto, or disable its own forced-HTTPS redirect.

Config reload fails or silently does nothing

Check that the admin endpoint is reachable and not disabled:

curl -s localhost:2019/config/ | head

If you set admin off, use systemctl restart caddy instead.

Slow first request after idle

Often DNS or the upstream cold-starting, not Caddy. Time each phase with:

curl -o /dev/null -s -w 'dns:%{time_namelookup} connect:%{time_connect} tls:%{time_appconnect} ttfb:%{time_starttransfer} total:%{time_total}\n' https://example.com

Mixed content warnings after enabling HTTPS

The site’s own database or templates still reference http:// URLs. Fix the application’s base URL setting and search and replace stored links. Server config cannot fully solve this.

r00t
r00t is a Server System Administrator with more than 7 years of experience in server administration, operating systems, and programming. They have a strong track record of managing, securing, and optimizing Linux-based infrastructure (Ubuntu, Debian, CentOS/AlmaLinux) as well as Windows Server, across on-premises, VPS, and cloud environments. Their expertise covers configuring and maintaining web servers (Nginx, Apache) and databases (MySQL/MariaDB, PostgreSQL). It also includes virtualization and containers (Proxmox, Docker), networking, firewalls, and security hardening. They are experienced in monitoring, backup and disaster recovery, and troubleshooting to keep services available and performing well. Skilled in Bash, Python, and PHP, they automate routine tasks, build maintenance scripts, and manage deployments, which makes operations more efficient and less error-prone. They are known for being meticulous, responsive during incidents, and willing to share knowledge with teams and the wider community. Outside of work, r00t enjoys experimenting with homelabs, open source software, and emerging infrastructure technologies.

Related Posts