Caddy

Use Caddy for a reverse proxy with automatic HTTPS and a tiny, readable configuration.

Beginner · about 2 hours · difficulty 1/5

Learn first: Reverse Proxies and Load Balancers

Caddy is a modern web server written in Go whose headline feature is automatic HTTPS: point a domain at the server, name it in the config, and Caddy obtains and renews certificates from Let's Encrypt or ZeroSSL on its own.

The Caddyfile

Configuration is famously short. A full HTTPS reverse proxy can be three lines: api.example.com { reverse_proxy localhost:3000 } Add file_server for static files, encode gzip zstd for compression, and handle_path /api/* blocks to route by path. Multiple upstreams in reverse_proxy enable load balancing with health checks.

Why teams choose it

  • Secure defaults: modern TLS settings, HTTP/2 and HTTP/3 enabled out of the box.
  • Sensible proxy headers (X-Forwarded-For, X-Forwarded-Proto) set automatically.
  • A JSON admin API for changing configuration at runtime without restarts.
  • Single static binary, easy to run in Docker.

Trade-offs

Nginx has a larger ecosystem, more tutorials and more battle-tested niche modules; Caddy plugins require building a custom binary (made easy by xcaddy). For small to medium deployments and side projects, Caddy's simplicity usually wins.

Pitfalls

  • Automatic HTTPS needs ports 80 and 443 reachable and DNS pointing at the server; certificate issuance fails otherwise.
  • Persist Caddy's data directory in containers or it will re-request certificates on every restart and hit rate limits.

You are ready to move on when you can serve your app over HTTPS with a Caddyfile, route /api to your backend and explain where Caddy stores its certificates.

Key concepts

  • Caddyfile syntax
  • Automatic HTTPS
  • reverse_proxy and load balancing
  • file_server for static assets
  • Admin API and JSON config
  • Running Caddy in Docker

Other options for this step

  • Nginx: Configure the most widely deployed web server and reverse proxy for your backend.
  • Apache HTTP Server: Work with Apache httpd, still common in PHP hosting, legacy stacks and enterprise environments.

Mini project

Replace an Nginx config with a Caddyfile that serves your frontend, proxies /api to two backend instances and gets certificates automatically.

Check yourself

What two conditions must be true for Caddy's automatic HTTPS to obtain a certificate?

Free resources