> ## Documentation Index
> Fetch the complete documentation index at: https://help.freakhosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Install Caddy Web Server with Automatic HTTPS

> Install Caddy on Ubuntu, Debian or AlmaLinux and get automatic HTTPS: put your domain in /etc/caddy/Caddyfile, open ports 80 and 443, then reload Caddy.

To get automatic HTTPS with Caddy, install it from Caddy's official repository, write your domain into `/etc/caddy/Caddyfile` (for example `example.com { reverse_proxy 127.0.0.1:3000 }`), make sure DNS points to the server and ports 80 and 443 are open, then run `sudo systemctl reload caddy`. Caddy gets a Let's Encrypt certificate by itself and renews it in the background.

| Difficulty | Time | Works on | Needs |
| - | - | - | - |
| Beginner | 10 minutes | Ubuntu 22.04 / 24.04, Debian 12 / 13, AlmaLinux / Rocky 9 / 10, Fedora | A domain, sudo, ports 80 and 443 free |

## Before you start

* Point the domain's `A` (and `AAAA`) record at your server: [point a domain](https://help.freakhosting.com/portals/other/how-to-point-a-domain-to-your-server.md).
* Stop Nginx or Apache if they run; only one program can use ports 80 and 443.
* Use a user with `sudo`. If you are `root`, leave out `sudo`.

Caddy is a web server and reverse proxy written in Go. Its main feature is automatic HTTPS: for every domain in its config, it requests a certificate from Let's Encrypt (with ZeroSSL as fallback), redirects HTTP to HTTPS and renews certificates without a cron job.

## How to install Caddy

> [tab] Ubuntu / Debian
>
> ```bash theme={null}
> sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl
> 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 chmod o+r /usr/share/keyrings/caddy-stable-archive-keyring.gpg
> sudo chmod o+r /etc/apt/sources.list.d/caddy-stable.list
> sudo apt update
> sudo apt install caddy
> ```
>
> The package starts Caddy as the systemd service `caddy` straight away.

> [tab] AlmaLinux / Rocky
>
> ```bash theme={null}
> sudo dnf install dnf-plugins-core
> sudo dnf copr enable @caddy/caddy
> sudo dnf install caddy
> sudo systemctl enable --now caddy
> ```
>
> On these systems the service is installed but not enabled, so the last line starts it.

Ubuntu and Debian also have a `caddy` package in their own repositories, but it is older. Caddy's repository gets updates first.

## How to open the firewall

> [tab] Ubuntu / Debian (ufw)
>
> ```bash theme={null}
> sudo ufw allow 80/tcp
> sudo ufw allow 443/tcp
> sudo ufw allow 443/udp
> ```

> [tab] AlmaLinux / Rocky (firewalld)
>
> ```bash theme={null}
> sudo firewall-cmd --permanent --add-service=http --add-service=https
> sudo firewall-cmd --permanent --add-port=443/udp
> sudo firewall-cmd --reload
> ```

Port 80 is needed to get certificates and redirect visitors. UDP 443 is for HTTP/3; HTTPS still works without it.

## How to serve a site with automatic HTTPS

Edit the Caddyfile:

```bash theme={null}
sudo nano /etc/caddy/Caddyfile
```

Replace the default `:80` block with your sites. Three common examples:

```text theme={null}
# Static website
example.com, www.example.com {
	root * /var/www/example.com
	file_server
	encode gzip
}

# Reverse proxy to an app on port 3000
app.example.com {
	reverse_proxy 127.0.0.1:3000
}

# PHP site through PHP-FPM (Ubuntu 24.04 socket)
blog.example.com {
	root * /var/www/blog
	php_fastcgi unix//run/php/php8.3-fpm.sock
	file_server
}
```

Check the file, then reload without downtime:

```bash theme={null}
caddy validate --config /etc/caddy/Caddyfile
sudo systemctl reload caddy
```

`validate` prints `Valid configuration` when the syntax is correct. Format the file neatly with `caddy fmt --overwrite /etc/caddy/Caddyfile`.

> [!NOTE]
>
> For the PHP example, PHP-FPM runs as `www-data` and Caddy runs as `caddy`. Add Caddy to the group so it can use the socket: `sudo usermod -aG www-data caddy`, then `sudo systemctl restart caddy`.

## How to check it worked

Open `https://example.com`. The padlock shows a certificate issued by Let's Encrypt. Watch Caddy get the certificate in the log:

```bash theme={null}
journalctl -u caddy --no-pager | tail -n 30
```

Look for `certificate obtained successfully`. Certificates and keys are stored in Caddy's data directory under `/var/lib/caddy`. Keep it on persistent disk and include it in backups.

## Frequently asked questions

### Caddy fails to get a certificate. What should I check?

The domain's DNS must point to this server, ports 80 and 443 must be reachable from the internet, and nothing else may be using them. Test from outside with [check if a port is open](https://help.freakhosting.com/portals/other/how-to-check-if-a-port-is-open-from-outside.md). Caddy retries with increasing waits, so fix the cause and run `sudo systemctl reload caddy`.

### Do I need Certbot with Caddy?

No. Caddy requests and renews certificates itself. Running Certbot as well only creates certificates Caddy does not use.

### Should I use Caddy or Nginx?

Caddy is quicker to set up and handles HTTPS for you. Nginx has more tutorials and fine-grained tuning options and is what most control panels use. Both are fine for small and medium sites. See [Nginx reverse proxy](https://help.freakhosting.com/portals/other/how-to-set-up-nginx-as-a-reverse-proxy.md).

### Can Caddy serve a site without a domain?

Yes, use `:80 { … }` for plain HTTP on the IP address. Automatic HTTPS from Let's Encrypt needs a domain name.

## Related guides

> [card] [VPS and dedicated server guides](https://help.freakhosting.com/portals/other/vps-and-dedicated-server-guides.md)
>
> Every server guide in one place.

> [card] [Node.js with PM2](https://help.freakhosting.com/portals/other/how-to-install-nodejs-and-run-apps-with-pm2.md)
>
> An app to put behind Caddy.

> [card] [Point a domain to your server](https://help.freakhosting.com/portals/other/how-to-point-a-domain-to-your-server.md)
>
> DNS first, then HTTPS.

> [card] [Install Nginx](https://help.freakhosting.com/portals/other/how-to-install-nginx.md)
>
> The classic alternative.

> [card] [Free SSL with Certbot](https://help.freakhosting.com/portals/other/how-to-get-a-free-ssl-certificate-with-certbot.md)
>
> HTTPS for Nginx and Apache.

***

> [!NOTE]
>
> **Checked against the official [Caddy install guide](https://caddyserver.com/docs/install), [Automatic HTTPS](https://caddyserver.com/docs/automatic-https) and [Running Caddy](https://caddyserver.com/docs/running) pages** on 4 November 2026; the example Caddyfile checked with `caddy validate` on Ubuntu 24.04 LTS (Caddy 2.6.2 from the Ubuntu archive). The Caddy repository install and certificate issuance were not tested. Commands can differ on other distributions or releases.

> [!NOTE]
>
> ### Need Extra Help?
>
> If you encounter any issues, our support team is ready to assist:
>
> * **Live Chat:** Quick assistance via our website.
> * **Support Ticket:** [Open a Ticket](https://freakhosting.com/clientarea/submitticket.php)
> * **Discord:** [Join our Community](https://discord.gg/freakhosting)
> * **Email:** [support@freakhosting.com](mailto:support@freakhosting.com)

> [!TIP]
>
> ### Save on Your Hosting
>
> Ready to upgrade your hosting? Use code **KB20** at checkout for **20% off** your first order!

***

**Last Updated:** November 2026


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.