caddy — automatic HTTPS web server
💬 "caddy Command"
caddy automatically issues and renews HTTPS (Let's Encrypt) certificates with a single line of configuration for an automatic HTTPS web server. Compared to nginx, its configuration is simpler.
It supports automatic HTTPS certificate issuance and renewal with a single line per domain. It uses two configuration formats: JSON and Caddyfile.
- Concept: Supports automatic HTTPS certificate issuance and renewal with a single line per domain.
- Key Features: Uses two configuration formats: JSON and Caddyfile.
- Advantages: Natively supports HTTP/3 (QUIC).
- Usage: Built-in support for static files, reverse proxy, and FastCGI.
Installation and Download
caddy can be installed via a package manager or an official script.
| Environment | Command |
|---|---|
| Ubuntu / Debian | sudo apt install caddy |
| Official Script | curl https://caddyserver.com/api/download?os=linux |
| macOS (brew) | brew install caddy |
| Docker | docker run -p 80:80 -p 443:443 caddy |
| Verification | caddy version |
Verify the installation with caddy --version.
Frequently Used Options
| Option | Description |
|---|---|
| caddy run | Run in foreground |
| caddy start | Run in background |
| caddy reload | Reload configuration (zero downtime) |
| caddy validate | Validate configuration syntax |
| sudo systemctl reload caddy | Reload service |
Three Essential Command Combinations
caddy run— Load Caddyfile and run in foregroundcaddy validate --config /etc/caddy/Caddyfile— Validate configurationsudo systemctl reload caddy— Zero-downtime reload
💬 "Show an example of using caddy on a real server"
Here are common situations encountered on a real server, organized step by step.
Step 1 · Installation Verification
Check if it's installed.
caddy version || sudo apt install -y caddy
Step 2 · Configuration Writing
Write the Caddyfile.
echo 'example.com {\n root * /var/www/html\n file_server\n}' > /etc/caddy/Caddyfile
Step 3 · Start
Start caddy and verify.
sudo systemctl restart caddy && curl -sI https://example.com/
Actual Execution Screen
Result of writing the Caddyfile and validating the configuration.
!caddy command execution result
Real server in operation
In Practice, It Is Used Like This
1. Migrating from nginx to Caddy
Situation — Migrate nginx 443 block to a Caddyfile.
echo 'example.com {\n root * /var/www/html\n file_server\n encode gzip\n}' > /etc/caddy/Caddyfile
Result — Configuration is complete with a single Caddyfile.
Key Points — No need for separate certbot cron or additional settings.
2. Verifying Automatic HTTPS
Situation — Verify automatic certificate issuance.
sudo systemctl restart caddy && sleep 5 && curl -sI https://example.com/
Result — HTTP/2 200 and server: Caddy are visible.
Key Points — Automatic HTTPS works in the browser.
Actual Execution Screen
Result of confirming that automatic HTTPS works after starting caddy.
!caddy command execution result 2
Real server in operation
Points to Note
- If the site address in the Caddyfile does not specify a port, it defaults to 80/443. Be cautious of port conflicts.
- Automatic HTTPS only works if the domain actually points to the caddy server. Certificate issuance will fail if DNS is not configured.
- When switching from nginx to Caddy, nginx-specific modules (e.g., Lua) may not have alternative implementations.
Source (HTML): https://games.aidebatehub.com/programs/linux/webserver/caddy.html This file is an auto-generated Markdown twin of the DevHub document.
AI Knowledge Hub
Visitor Comments