Catalog / Caddy Web Server Cheatsheet
Caddy Web Server Cheatsheet
A quick reference guide to the Caddy web server, covering its configuration syntax, common directives, and usage examples.
Caddyfile Basics
Caddyfile Structure
A Caddyfile defines the configuration for one or more sites.
|
Caddyfile is case-insensitive. |
Site Addresses
|
Matches requests to |
|
Matches requests to |
|
Matches requests to any subdomain of |
|
Matches HTTP requests to |
|
Matches HTTPS requests to |
|
Matches requests to |
Basic Directives
|
Sets the root directory for serving files. |
|
Enables the file server to serve static files. |
|
Enables Gzip compression for responses. |
|
Configures logging. |
|
Uses a self-signed certificate for TLS (not recommended for production). |
|
Proxies requests to a backend server. |
Common Directives
Redirection
|
Redirects |
|
Permanent redirect (301 status code). |
|
Temporary redirect (302 status code) to a different domain. |
|
Redirects ACME challenge requests to a staging server. |
Error Handling
|
Handles errors and returns a 500 error with a custom message. |
|
Proxies error requests to another server. |
|
Serves a custom error page. |
Header Manipulation
|
Sets the Strict-Transport-Security header for HTTPS. |
|
Removes the Server header. |
|
Sets CORS headers for the |
|
Adds a custom header |
Advanced Configuration
Reverse Proxy
|
|
Load Balancing
|
Basic load balancing between two backend servers. |
|
Load balancing with a specific policy (round_robin, first, random, least_conn, header). |
|
Configures health checks for backend servers. |
TLS Configuration
|
Uses Caddy’s internal CA for issuing certificates (for development). |
|
Uses Cloudflare DNS for ACME DNS challenge. |
|
Specifies the paths to a custom certificate and key. |
|
Specifies the TLS protocol versions. |
Caddy CLI
Basic Commands
|
Displays the Caddy version. |
|
Starts Caddy in the background. |
|
Stops Caddy. |
|
Reloads the Caddy configuration without downtime. |
|
Converts a Caddyfile to JSON configuration. |
Configuration Management
|
Starts a simple file server. |
|
Starts Caddy in the foreground (useful for debugging). |
|
Prints Caddy’s environment variables. |
Service Management (systemd)
Caddy can be managed as a systemd service. Ensure the Caddyfile is in the correct location (e.g.,
|