DEV Community

Alex Spinov
Alex Spinov

Posted on

Caddy Has a Free API That Gives You Automatic HTTPS With Zero Configuration

Caddy is a web server that gets HTTPS certificates automatically. No certbot, no cron jobs, no certificate renewal scripts. Just point it at your domain.

Quick Start

# Install
sudo apt install -y caddy

# Serve a site with automatic HTTPS
caddy reverse-proxy --from example.com --to localhost:3000
Enter fullscreen mode Exit fullscreen mode

That's it. Caddy obtains a Let's Encrypt certificate, configures HTTPS, and proxies traffic.

Caddyfile (Config)

example.com {
    reverse_proxy localhost:3000
}

api.example.com {
    reverse_proxy localhost:8080
}

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

Reverse Proxy with Load Balancing

example.com {
    reverse_proxy localhost:3001 localhost:3002 localhost:3003 {
        lb_policy round_robin
        health_uri /health
        health_interval 10s
    }
}
Enter fullscreen mode Exit fullscreen mode

Caddy vs Nginx vs Traefik

Feature Caddy Nginx Traefik
Auto HTTPS Yes No Yes
Config Caddyfile nginx.conf YAML/Docker labels
Hot reload Yes Yes Yes
Reverse proxy Yes Yes Yes
Docker labels Plugin No Native
Learning curve Easy Medium Medium

API

# Caddy has a REST API for dynamic config
curl http://localhost:2019/config/
curl -X POST http://localhost:2019/load -H "Content-Type: application/json" -d @config.json
Enter fullscreen mode Exit fullscreen mode

The Bottom Line

Caddy eliminates 90% of web server configuration. Automatic HTTPS, simple Caddyfile syntax, hot reload. If you're still writing Nginx configs and certbot cron jobs, switch to Caddy.


Need to automate data collection or build custom scrapers? Check out my Apify actors for ready-made tools, or email spinov001@gmail.com for custom solutions.

Top comments (0)