DEV Community

Alex Spinov
Alex Spinov

Posted on

Caddy Server Is Free — Auto-HTTPS Reverse Proxy in One Line

Nginx Is Powerful. Caddy Is Simple.

Caddy automatically provisions and renews SSL certificates. No certbot, no cron, no manual renewal. One line of config gives you HTTPS.

Install

# Ubuntu/Debian
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf https://dl.cloudsmith.io/public/caddy/stable/gpg.key | sudo apt-key add -
sudo apt install caddy

# Or just download the binary
curl -o caddy https://caddyserver.com/api/download?os=linux&arch=amd64
Enter fullscreen mode Exit fullscreen mode

Reverse Proxy in One Line

caddy reverse-proxy --from yourdomain.com --to localhost:3000
Enter fullscreen mode Exit fullscreen mode

That is it. Auto-HTTPS. Auto-renewal. Zero configuration files.

Caddyfile (Multiple Services)

yourdomain.com {
    reverse_proxy localhost:3000
}

api.yourdomain.com {
    reverse_proxy localhost:8080
}

static.yourdomain.com {
    root * /var/www/static
    file_server
}
Enter fullscreen mode Exit fullscreen mode

Caddy API

import requests

# Load config
def update_config(config):
    r = requests.post("http://localhost:2019/load",
                      headers={"Content-Type": "application/json"},
                      json=config)
    return r.status_code == 200

# Add a route dynamically
def add_route(domain, upstream):
    config = {
        "apps": {"http": {"servers": {"srv0": {
            "listen": [":443"],
            "routes": [{
                "match": [{"host": [domain]}],
                "handle": [{"handler": "reverse_proxy", "upstreams": [{"dial": upstream}]}]
            }]
        }}}}
    }
    return update_config(config)
Enter fullscreen mode Exit fullscreen mode

Caddy vs Nginx vs Traefik

Feature Caddy Nginx Traefik
Auto-HTTPS Yes No (need certbot) Yes
Config Simple Complex Medium
Hot reload Yes Partial Yes
API REST None REST
Performance High Highest High
Learning curve 5 min 1 day 2 hours

More | GitHub


Need custom dev tools, scrapers, or API integrations? I build automation for dev teams. Email spinov001@gmail.com — or explore awesome-web-scraping.
Also: Neon Free Postgres | Vercel Free API | Hetzner 4x More Server
NEW: I Ran an AI Agent for 16 Days — What Works

Top comments (0)