DEV Community

Alex Spinov
Alex Spinov

Posted on

Caddy Has a Free Web Server With Automatic HTTPS

Caddy is a free, open-source web server that automatically enables HTTPS for all your sites. No configuration needed for SSL certificates.

What Is Caddy?

Caddy is a modern web server written in Go. Its killer feature: automatic HTTPS with zero configuration.

Key features:

  • Automatic HTTPS (Let's Encrypt + ZeroSSL)
  • Automatic certificate renewal
  • HTTP/2 and HTTP/3 support
  • Reverse proxy
  • Load balancing
  • File server
  • Caddyfile (simple config format)
  • API-driven configuration
  • Single binary
  • Extensible with plugins

Quick Start

# Install
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf https://dl.cloudsmith.io/public/caddy/stable/gpg.key | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
sudo apt update && sudo apt install caddy

# Or download binary
https://caddyserver.com/download
Enter fullscreen mode Exit fullscreen mode

Caddyfile Examples

Static File Server

localhost {
    root * /var/www/html
    file_server
}
Enter fullscreen mode Exit fullscreen mode

Reverse Proxy

myapp.example.com {
    reverse_proxy localhost:3000
}
Enter fullscreen mode Exit fullscreen mode

That's it. Caddy automatically gets an SSL certificate for myapp.example.com.

Multiple Sites

app.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

All with automatic HTTPS.

Load Balancing

myapp.example.com {
    reverse_proxy localhost:3001 localhost:3002 localhost:3003
}
Enter fullscreen mode Exit fullscreen mode

Caddy vs Nginx

Feature Nginx Caddy
Auto HTTPS No (certbot) Yes
Config Complex Simple
HTTP/3 Experimental Built-in
Reload Manual Automatic
Binary C compilation Single Go binary
API config No Yes

Docker

services:
  caddy:
    image: caddy:2
    ports:
      - 80:80
      - 443:443
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile
      - caddy_data:/data
volumes:
  caddy_data:
Enter fullscreen mode Exit fullscreen mode

With 61K+ GitHub stars. The web server that does HTTPS for you.


Serving scraped data via API? Check out my tools on Apify. Custom solutions: spinov001@gmail.com

Top comments (0)