Caddy is an open-source web server and reverse proxy written in Go. Caddy is best known for automatic HTTPS: when a domain points to your server, Caddy obtains a certificate from Let's Encrypt and renews it in time. Its configuration is stored in a short text file called the Caddyfile. You can describe a static website or a reverse proxy for an app in just a few lines.
In this guide, we’ll show you two ways to set it up: the easy way, as a One-Click App, which gets your static website online with HTTPS in just a few minutes, and a manual installation with Docker Compose, which lets you use Caddy as a reverse proxy with your own Caddyfile. At the end, you’ll find some typical Caddyfile examples.
Caddy is a good fit for a VPS if:
- You want to publish a static website, such as a business card site, landing page, or documentation generated with Hugo, Jekyll, Astro, or another generator.
- You want HTTPS without the manual work. Caddy takes care of certificates and renewals itself, so you don’t need an additional tool like Certbot.
- You want to make multiple apps on one server available under their own subdomains. One
reverse_proxyline per app is all you need. - You find nginx or Apache configuration too extensive. A Caddyfile is much shorter and reads almost like plain text.
Caddy is less suitable if you want to run PHP applications like WordPress. Caddy can only pass PHP requests to a separate PHP-FPM service, which you would have to set up yourself. There are more suitable One-Click Apps for this; see Set Up a Website with ZAP Webspace and Set Up WordPress.
The One-Click App and a custom installation differ more with Caddy than with most apps. Your VPS’s One-Click Apps include their own proxy. It uses ports 80 and 443, obtains an HTTPS certificate for each app, and forwards requests to the app. Caddy therefore runs behind this proxy and only serves your files.
| Caddy as a One-Click App | Custom Installation with Docker Compose | |
|---|---|---|
| Intended for | Static website | Static websites and reverse proxy for your own apps |
| HTTPS certificate | Obtained by the One-Click Apps proxy | Obtained by Caddy itself |
| Custom Caddyfile | No, fixed default configuration | Yes, freely customizable |
| Ports 80 and 443 | Used by the One-Click Apps proxy | Used by Caddy |
| Setup | A few clicks in the dashboard | Console, Docker, Caddyfile |
If you only need Caddy to make other One-Click Apps available over HTTPS, you don’t have to do anything: the One-Click Apps proxy already handles that for each app.
The quickest way to get a website running with Caddy is through your VPS’s One-Click Apps. ZapX sets up the domain, certificate, and redirect from HTTP to HTTPS for you. All you need to do is upload your files.
- A Linux VPS (Debian or Ubuntu) with One-Click Apps set up. See Set Up One-Click Apps for instructions.
- At least 256 MB of free RAM (512 MB recommended) and 1 to 2 GB of storage, plus space for your website. Caddy itself uses very few resources.
- Open your VPS in the ZapX dashboard and go to the One-Click Apps tab.
- Search for Caddy in the App catalog and click Install app.
- Leave Use a custom subdomain or zap.cloud enabled and choose an address, such as a subdomain under zap.cloud or your own domain. Without a domain, the website is only accessible over HTTP.
- No other information is required. Caddy has no app configuration or login credentials.
- Click Queue installation.
After one or two minutes, the app will appear as “Online” in your list of installed apps.
Open the website using the Access link on the app card. You’ll see the “Caddy works!” welcome page. The address is immediately accessible over HTTPS, and the proxy redirects HTTP requests to HTTPS.
The welcome page describes an installation as a system package (files in /var/www/html, Caddyfile at /etc/caddy, systemctl reload caddy). The One-Click App works differently: the domain and certificate are already set up, and your files belong in the folder described in the next section.
Caddy serves all files from the /usr/share/caddy folder in the container. This folder is stored as a Docker volume on your VPS. Find the exact path over SSH by running:
docker volume ls | grep caddy-site
The name will look something like this: APP_ID_caddy-site. The files are then located at:
/var/lib/docker/volumes/APP_ID_caddy-site/_data
To publish your website:
- Connect to your VPS as
rootover SFTP and open the folder above. - Replace the provided
index.htmlwith your own homepage, then upload your other files and folders. - Reload the website in your browser. You don’t need to restart the app—Caddy serves new files immediately.
Caddy looks for an index.html in each folder. So a file at blog/index.html is available at https://your-domain/blog/. If a file is missing, Caddy returns a 404 error.
Change the app’s primary address in its settings (gear icon), under App actions, by selecting Change next to Custom subdomain. To make your website available under www or a second domain as well, enter it under Additional domains and click Add.
If the domain is registered with ZAP-Hosting or in your connected Cloudflare account, ZapX will create the DNS record for you. If you use another DNS provider, create an A record pointing to the IP address shown in the dashboard. The certificate for the new domain will then be obtained automatically.
The One-Click App always starts Caddy with the provided configuration at /etc/caddy/Caddyfile: a static website served from /usr/share/caddy. Caddy doesn’t read a Caddyfile that you put in the caddy-config volume (at /config in the container). Caddy only stores its own state there. For redirects, a reverse proxy, password protection, or custom headers, use the manual installation described below.
The One-Click App also doesn’t include PHP, databases, or server-side logic. For a website with PHP, use ZAP Webspace.
Update Caddy in the app’s settings (gear icon), under App update. Click Check for updates, then install a new version using Apply update. If the page says the app is up to date, there isn’t a newer version in the app catalog.
Your website files are stored in the caddy-site volume and are retained when you update the app or select Reinstall app. Still, back them up regularly—for example, by using SFTP to copy them to your computer or by using Backups in your VPS dashboard. When you uninstall the app, you can also delete its volumes. If you do, your website will be deleted too.
The rest of this guide describes a manual installation of Caddy with Docker Compose on your VPS. This option is right for you if you need your own Caddyfile—for example, to use Caddy as a reverse proxy for your own apps—and you aren’t using One-Click Apps on the server.
If One-Click Apps are set up on your VPS, their proxy is already using ports 80 and 443. Your own Caddy installation won’t start and may report an error such as “port is already allocated” or “address already in use.” In this case, use the One-Click App or a separate VPS for Caddy.
- A Linux VPS with Debian or Ubuntu and SSH access; see First Access via SSH.
- Docker and Docker Compose (Compose v2); see Install Docker. Check the installation with
docker --versionanddocker compose version. - A domain or subdomain whose A record (and AAAA record, if present) points to your VPS’s IP address, for example
example.com. - Ports 80 and 443 are available. If nginx or Apache is already running, check with
ss -ltnp | grep -E ':(80|443) '.
Caddy needs few resources. You’ll only need more RAM and CPU if you have many simultaneous visitors or large files.
| Hardware | Minimum | Recommended |
|---|---|---|
| CPU | 1 vCPU core | 1 vCPU core |
| RAM | 256 MB | 512 MB |
| Storage | 1 GB | 2 GB plus space for your website |
Caddy needs port 80 for Let's Encrypt certificate validation and redirects to HTTPS, port 443 for HTTPS, and UDP port 443 for HTTP/3. With ufw, allow only SSH and these ports:
ufw allow OpenSSH
ufw allow 80/tcp
ufw allow 443/tcp
ufw allow 443/udp
ufw enable
Ports published by Docker with ports: are accessible from outside even if ufw blocks them. This is intentional for Caddy. For your other apps, however, make sure to bind them only to 127.0.0.1 or don’t publish any ports if Caddy is in front of them. See Managing the Firewall on Linux for more information.
Create a directory for Caddy, with one folder for the configuration and another for your website:
mkdir -p /opt/caddy/conf /opt/caddy/site
cd /opt/caddy
nano compose.yaml
Add this content:
services:
caddy:
image: caddy:2.11
restart: unless-stopped
cap_add:
- NET_ADMIN
ports:
- "80:80"
- "443:443"
- "443:443/udp"
volumes:
- ./conf:/etc/caddy
- ./site:/srv
- caddy_data:/data
- caddy_config:/config
extra_hosts:
- "host.docker.internal:host-gateway"
networks:
default:
name: caddy
volumes:
caddy_data:
caddy_config:
The most important lines:
image: caddy:2.11is the official image, pinned to version 2.11. You’ll automatically get bug fixes for this version whenever you update.portspublishes HTTP, HTTPS, and HTTP/3.cap_add: NET_ADMINallows Caddy to use larger buffers for HTTP/3../conf:/etc/caddymounts the entire configuration folder, not just the file. This ensures Caddy reliably picks up Caddyfile changes when reloading../site:/srvis the folder for your website.caddy_datacontains certificates and keys. This volume must never be lost; otherwise, Caddy will have to obtain all certificates again and may quickly hit Let's Encrypt limits.extra_hostsmakes the VPS itself accessible from the container ashost.docker.internal, whilenetworksgives the Docker network the fixed namecaddy. You need both for a reverse proxy.
Now create the Caddyfile:
nano /opt/caddy/conf/Caddyfile
Enter your domain. This block serves the files from /srv and compresses them:
example.com {
root * /srv
encode
file_server
}
Create an initial homepage and start Caddy:
echo '<h1>Hello from Caddy</h1>' > /opt/caddy/site/index.html
docker compose up -d
docker compose logs -f caddy
The logs show Caddy obtaining the certificate for your domain. Once you see certificate obtained successfully, everything is ready. Exit the log view with Strg+C.
Open https://example.com in your browser. You’ll see your homepage, and the lock icon indicates a valid certificate. Caddy automatically redirects requests from http:// to HTTPS.
If the certificate can’t be obtained, it’s almost always a DNS or firewall issue: check that the domain points to your VPS’s IP address, that ports 80 and 443 are open, and that an AAAA record isn’t pointing to an incorrect IPv6 address.
A custom reverse proxy with nginx requires two tools: nginx for forwarding, as described in Set Up a Reverse Proxy with nginx, and Certbot for the certificate, as described in Create an SSL Certificate (Let's Encrypt). Caddy handles both on its own: as soon as you add a domain name to the Caddyfile, Caddy obtains and renews the certificate and redirects HTTP to HTTPS. There’s no need for a separate TLS block or cron job.
So, use either Caddy or nginx with Certbot on a server, not both on ports 80 and 443 at the same time. You’ll find forwarding examples below under “Caddyfile: Typical Examples.”
After each change to the Caddyfile, reload the configuration without interruption:
cd /opt/caddy
docker compose exec -w /etc/caddy caddy caddy reload
If the Caddyfile contains an error, Caddy keeps the old configuration and shows the line with the error. You can check the file first with docker compose exec caddy caddy validate --config /etc/caddy/Caddyfile.
Find more tips on securing your server in Linux Security Tips.
Back up the Caddyfile, your website, and the volume containing the certificates:
cd /opt/caddy
tar czf /root/caddy-files-$(date +%F).tar.gz conf site compose.yaml
docker run --rm -v caddy_caddy_data:/data -v /root:/backup alpine tar czf /backup/caddy-data-$(date +%F).tar.gz -C /data .
The volume name caddy_caddy_data is based on the folder name caddy. You can find the exact name with docker volume ls. Don’t store the backup only on the VPS itself.
With the caddy:2.11 tag, you’ll get bug fixes for this version by running:
cd /opt/caddy
docker compose pull
docker compose up -d
To use a new major version, enter the new tag in compose.yaml—for example, caddy:2.12 once it’s available—and run the same commands. Read the release notes first. Check the installed version with docker compose exec caddy caddy version.
The following blocks are for the manual installation. Replace the domains with your own, then reload Caddy as described above.
This Caddyfile serves the website at example.com and permanently redirects www.example.com there. Caddy obtains a certificate for both names:
example.com {
root * /srv
encode
file_server
}
www.example.com {
redir https://example.com{uri} permanent
}
If an app also runs in Docker, connect it to the caddy network. Add this to the app’s compose.yaml:
networks:
default:
name: caddy
external: true
Restart the app with docker compose up -d. Caddy can then reach it using its service name and container port, so you no longer need to expose the app’s port externally. For an app with the service name myapp on port 3000:
app.example.com {
reverse_proxy myapp:3000
}
If the app runs without Docker or uses a published port, you can reach it with reverse_proxy host.docker.internal:8080. This only works if the app isn’t listening exclusively on 127.0.0.1, because that’s a different address from the container’s perspective. In this case, block the app’s port from external access in the firewall.
Caddy sets the X-Forwarded-For, X-Forwarded-Proto, and X-Forwarded-Host headers automatically. Many apps also need to be configured to run behind a proxy and to use their public address. See the documentation for the relevant app.
If an app doesn’t have its own login, you can protect it with Basic Auth. First, generate a password hash. Caddy never stores the password itself:
cd /opt/caddy
docker compose exec caddy caddy hash-password
Enter the password twice and copy the output, which starts with $2a$. Add it to the Caddyfile along with a username:
intern.example.com {
basic_auth {
admin HASH_AUS_DER_AUSGABE
}
reverse_proxy myapp:3000
}
- No PHP out of the box: Caddy serves files and forwards requests. PHP pages need an additional PHP-FPM service, which Caddy connects to using
php_fastcgi. - Not a replacement for a firewall: Caddy only protects the services you publish through it. Ports published directly by other containers remain accessible.
- Certificates require accessible domains: Caddy can’t obtain a Let's Encrypt certificate for addresses that don’t publicly point to your VPS.
- One web server per port: Caddy and another web server, such as nginx or Apache, can’t both use ports 80 and 443 at the same time.
You’ve set up Caddy on your VPS: as a One-Click App for a static website with automatic HTTPS, or manually with your own Caddyfile, which lets you serve websites, publish apps through a reverse proxy, and protect areas with a password.
Want to get a website online without using the console or configuring anything? Choose the easy option: the One-Click App, as described above under “Easy Option: Caddy as a One-Click App.”
