DEV Community

Alex Spinov
Alex Spinov

Posted on

Caddy Has a Free Web Server That Auto-Configures HTTPS — Replace Nginx + Certbot With 3 Lines

The HTTPS Problem

Setting up HTTPS with Nginx:

  1. Install Nginx
  2. Install Certbot
  3. Run Certbot to get Let's Encrypt certificate
  4. Configure Nginx with SSL paths
  5. Set up cron job for certificate renewal
  6. Handle redirect from HTTP to HTTPS

Caddy does all of this automatically. Point it at a domain, it handles the rest.

What Caddy Gives You

Automatic HTTPS

# Caddyfile — that's the ENTIRE config
example.com {
    reverse_proxy localhost:3000
}
Enter fullscreen mode Exit fullscreen mode

Caddy automatically:

  • Gets a Let's Encrypt certificate
  • Redirects HTTP → HTTPS
  • Renews certificates before they expire
  • Configures OCSP stapling
  • Uses modern TLS settings

Reverse Proxy

example.com {
    reverse_proxy /api/* localhost:8080
    reverse_proxy /ws/* localhost:8081
    root * /var/www/html
    file_server
}
Enter fullscreen mode Exit fullscreen mode

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

SPA Routing

example.com {
    root * /var/www/app
    try_files {path} /index.html
    file_server
}
Enter fullscreen mode Exit fullscreen mode

Perfect for React, Vue, Angular — all 404s fall back to index.html.

API Config (JSON)

curl localhost:2019/config/ -d '{
  "apps": {
    "http": {
      "servers": {
        "main": {
          "listen": [":443"],
          "routes": [{
            "handle": [{
              "handler": "reverse_proxy",
              "upstreams": [{"dial": "localhost:3000"}]
            }]
          }]
        }
      }
    }
  }
}'
Enter fullscreen mode Exit fullscreen mode

Update configuration at runtime via API. No restarts. No downtime.

Quick Start

# Install
brew install caddy  # or apt, yum, docker

# Serve current directory
caddy file-server --listen :8080

# Reverse proxy with auto-HTTPS
caddy reverse-proxy --to localhost:3000
Enter fullscreen mode Exit fullscreen mode

Why This Matters

HTTPS shouldn't require 6 steps and 3 tools. Caddy makes TLS automatic, so you can focus on your application instead of your certificate infrastructure.


Serving web data APIs? Check out my web scraping actors on Apify Store — structured data for your applications. For custom solutions, email spinov001@gmail.com.

Top comments (0)