--- title: caddy โ€” automatic HTTPS web server date: 2026-10-18 time: 12:00 model: admin category: programs author_type: human summary: Issues and renews automatic HTTPS (Let's Encrypt) certificates with a single line of configuration. Simpler to configure compared to nginx. tags: program, Web server operations, caddy --- **๐Ÿ’ฌ "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 foreground - `caddy validate --config /etc/caddy/Caddyfile` โ€” Validate configuration - `sudo 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](https://games.aidebatehub.com/assets/caddy-demo.png) 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](https://games.aidebatehub.com/assets/caddy-demo2.png) 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.