If you've ever set up Nginx and found SSL configuration tedious — running Certbot separately, setting up cron jobs for renewal — Caddy Web Server is your answer. Caddy is a modern web server that provisions HTTPS automatically via Let's Encrypt. Just put your domain name in the config file and Caddy takes care of everything else.
📋 Table of Contents
What is Caddy Web Server?
Caddy is an open-source web server written in Go, designed for simplicity. Its defining feature is automatic HTTPS certificate provisioning from Let's Encrypt — no Certbot, no cron jobs. Simply declare your domain in the Caddyfile and Caddy handles the rest.
Caddy v2 is a complete rewrite with improved API, performance, and plugin system. It is the current stable release suitable for production workloads.
- Automatic HTTPS: Issues and renews Let's Encrypt certs automatically
- HTTP/2 & HTTP/3: Both enabled out-of-the-box
- Caddyfile: Much simpler than Nginx configuration syntax
- Zero-downtime reload: Reload config without dropping connections
- Admin API: Control Caddy via REST API
Caddy vs Nginx vs Apache Comparison
| Feature | Caddy v2 | Nginx | Apache |
|---|---|---|---|
| Auto HTTPS (Let's Encrypt) | ✅ Built-in | ❌ Requires Certbot | ❌ Requires mod_ssl |
| Config Syntax | 🟢 Very simple (Caddyfile) | 🟡 Medium complexity | 🔴 Complex |
| HTTP/3 Support | ✅ Built-in | 🟡 Manual setup | 🟡 Manual setup |
| RAM Usage (idle) | ~15-30 MB | ~5-10 MB | ~20-50 MB |
| PHP Support | ✅ FastCGI | ✅ FastCGI | ✅ mod_php |
| Reverse Proxy | ✅ Built-in | ✅ Built-in | 🟡 mod_proxy |
| Plugin System | ✅ xcaddy | 🔴 Compile-time only | ✅ Modules |
| Community / Docs | 🟡 Growing | ✅ Very large | ✅ Very large |
Installing Caddy on Ubuntu
Install via the official Caddy apt repository for automatic updates:
# Install dependencies
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl
# Add Caddy GPG key and repository
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
# Install Caddy
sudo apt update
sudo apt install caddy
Verify installation:
caddy version
# Should output: v2.9.x (or newer)
sudo systemctl status caddy
# Should show: active (running)
Caddyfile Basics
Caddy uses /etc/caddy/Caddyfile as its main config file. Here's a simple example:
# /etc/caddy/Caddyfile
# Simplest possible server - automatic HTTPS
example.com {
root * /var/www/html
file_server
}
# Reverse proxy to an app on port 3000
api.example.com {
reverse_proxy localhost:3000
}
That's all it takes. Caddy will obtain SSL certificates for both domains from Let's Encrypt automatically. To apply changes:
sudo systemctl reload caddy
# Or via admin API
caddy reload --config /etc/caddy/Caddyfile
Commonly Used Directives
root * /path— set the document rootfile_server— serve static filesreverse_proxy HOST:PORT— proxy requests upstreamencode gzip zstd— enable compressionheader— set response headersredir— redirect URLslog— enable access logging
Automatic HTTPS with a Real Domain
Before Caddy can issue SSL, ensure your domain's DNS points to the VPS IP, and ports 80/443 are open:
# Open ports with UFW
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw allow 443/udp # For HTTP/3 (QUIC)
# Verify DNS before proceeding
dig +short yourdomain.com
# Must return your VPS IP address
Once DNS resolves correctly, add your domain to the Caddyfile and reload. Caddy completes the ACME challenge in under 30 seconds.
Configuring Caddy with PHP-FPM
Install PHP-FPM first:
sudo apt install php8.3-fpm php8.3-mysql php8.3-curl php8.3-xml php8.3-mbstring php8.3-zip -y
sudo systemctl enable --now php8.3-fpm
Update your Caddyfile to support PHP:
yourdomain.com {
root * /var/www/html
encode gzip
php_fastcgi unix//run/php/php8.3-fpm.sock
file_server
log {
output file /var/log/caddy/access.log
}
}
sudo mkdir -p /var/log/caddy
sudo chown caddy:caddy /var/log/caddy
sudo systemctl reload caddy
Test with a PHP info page:
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
# Visit https://yourdomain.com/info.php — should show PHP info page
Using Caddy with WordPress
Install MySQL and additional WordPress PHP extensions:
sudo apt install mysql-server php8.3-imagick php8.3-gd php8.3-intl -y
# Create WordPress database
sudo mysql -e "CREATE DATABASE wordpress CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
sudo mysql -e "CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'SecurePassword123!';"
sudo mysql -e "GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';"
Caddyfile for WordPress:
yourdomain.com {
root * /var/www/wordpress
encode gzip zstd
php_fastcgi unix//run/php/php8.3-fpm.sock
file_server
# WordPress permalinks (equivalent to Nginx try_files)
@notStatic {
not path /wp-content/uploads/*
not file
}
rewrite @notStatic /index.php?{query}
# Security headers
header X-Content-Type-Options nosniff
header X-Frame-Options SAMEORIGIN
header Referrer-Policy strict-origin-when-cross-origin
}
Multiple Domains on One VPS
Caddy makes virtual hosting trivial. Add multiple server blocks to your Caddyfile:
# site1.com with PHP
site1.com {
root * /var/www/site1
encode gzip
php_fastcgi unix//run/php/php8.3-fpm.sock
file_server
}
# site2.com - static only
site2.com {
root * /var/www/site2
encode gzip
file_server
}
# api.site3.com - reverse proxy
api.site3.com {
reverse_proxy localhost:8080
}
# Redirect www to non-www
www.site1.com {
redir https://site1.com{uri} permanent
}
Each domain automatically receives its own SSL certificate. No manual configuration needed.
Performance Tuning
Caddy's defaults are good, but you can optimize further:
# Global options block (top of Caddyfile)
{
log {
level WARN
}
# Disable admin API if not needed (more secure)
admin off
# Email for Let's Encrypt notifications
email [email protected]
}
yourdomain.com {
root * /var/www/html
encode zstd gzip # zstd first (faster on supporting browsers)
file_server
# Cache static assets
@static path *.css *.js *.png *.jpg *.webp *.woff2
header @static Cache-Control "public, max-age=31536000, immutable"
encode {
gzip
zstd
minimum_length 1024
}
}
Frequently Asked Questions
What is Caddy Web Server?
Caddy is an open-source web server written in Go that automatically provisions and renews HTTPS certificates from Let's Encrypt. No separate SSL setup or Certbot needed.
How does Caddy compare to Nginx?
Caddy provides automatic SSL and a simpler Caddyfile configuration. Nginx has a larger ecosystem, slightly lower idle RAM usage, and more mature advanced load balancing documentation.
What VPS specs do I need for Caddy?
Caddy runs on a VPS with 512 MB RAM or more. For typical websites, 1 GB RAM, 1 vCPU, and 20 GB SSD is more than sufficient.
Does Caddy support PHP?
Yes. Use PHP-FPM with the php_fastcgi directive in your Caddyfile. This supports WordPress, Laravel, and any PHP application fully.
Does Caddy auto-renew SSL certificates?
Yes. Caddy manages the full certificate lifecycle automatically, renewing before expiry. No cron jobs or manual steps are ever needed.
Can I host multiple domains on one VPS with Caddy?
Absolutely. Add separate server blocks in your Caddyfile. Each domain gets its own automatic SSL certificate. Caddy supports unlimited virtual hosts.
Conclusion
Caddy Web Server is an excellent choice for VPS deployments that need HTTPS quickly and without complexity. Its automatic SSL provisioning, simple Caddyfile syntax, and built-in HTTP/3 support make it a compelling alternative to Nginx — especially for developers and teams who value simplicity over raw configuration flexibility.
Need a VPS to run Caddy on? Check out AsiaGB VPS plans — SSD storage, 99% uptime, starting from ฿500/month.
