Skip to content

Caddy Installation & Config Guide

Caddy is a powerful modern Web server written in Go. Its biggest feature is Automatic HTTPS enabled by default (automatically applies for and renews certificates via Let's Encrypt), and its configuration file (Caddyfile) is extremely concise and readable.

HTTPS

Caddy Installation

Linux (Debian / Ubuntu / Raspberry Pi)

Install necessary dependencies and add official key:

bash
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl
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

Update and install:

bash
sudo apt update
sudo apt install caddy

Check status:

bash
systemctl status caddy

Linux (CentOS / RHEL / Fedora)

bash
sudo yum install yum-plugin-copr
sudo yum copr enable @caddy/caddy
sudo yum install caddy

Windows

  1. Go to Caddy Official Download Page to download the Windows executable (.exe).
  2. Rename the downloaded file to caddy.exe and place it in a suitable directory (e.g., C:\caddy).
  3. Open PowerShell or CMD in that directory to run.

API Command Cheat Sheet

CommandDescription
caddy runRun Caddy in foreground
caddy startStart Caddy in background
caddy stopStop running Caddy
caddy reloadReload configuration (run in directory with config file)
caddy fmt --overwriteFormat Caddyfile and save over it

Caddyfile Configuration Examples

The default configuration file for Caddy is usually located at /etc/caddy/Caddyfile.

1. Minimalist Static Site

For local testing, a one-line config is enough:

nginx
:8080

file_server

This starts a static file server on port 8080, with the current running directory as root.

2. Production Static Site (Auto HTTPS)

nginx
example.com {
    root * /var/www/html
    file_server
}
  • Note: Replace example.com with your real domain and ensure the domain resolves to the server IP. Caddy will automatically apply for an SSL certificate and enable HTTPS.

3. Reverse Proxy

Forward traffic to backend service (e.g., port 3000):

nginx
api.example.com {
    reverse_proxy localhost:3000
}

It's that simple! Caddy automatically handles HTTPS, Header forwarding, etc.

4. Common Directive Combinations

nginx
domain.com {
    # Enable Gzip compression
    encode gzip

    # Reverse proxy
    reverse_proxy 127.0.0.1:8080

    # Log configuration
    log {
        output file /var/log/caddy/access.log
    }
}

All resources are from the open-source community. Disclaimer