Caddy
Caddy
A web server with automatic HTTPS. Written in Go, simple to configure.
Caddy
A web server with automatic HTTPS. Written in Go, simple to configure.
Caddy is a modern web server written in Go, and its most distinctive feature is automatic HTTPS. Matt Holt began developing it in 2015, and it integrates automatically with Let's Encrypt, handling certificate issuance, renewal, and even OCSP stapling automatically.
Its configuration file (Caddyfile) is very concise, making configuration easier than with Nginx or Apache. With just a few lines of configuration, you can implement reverse proxying, load balancing, file serving, compression, header manipulation, and more.
It is distributed as a static binary with no dependencies, and is particularly useful in container environments. Runtime configuration changes are possible through a JSON API, and functionality can be extended through a module system. HTTP/3 (QUIC) is also supported by default.
In practice, it is used for local HTTPS setup in development environments, as a production web server for small to medium-sized projects, and as an alternative to Kubernetes Ingress. Nginx is still widely used for large-scale traffic, but Caddy's share is growing thanks to its convenience.
# Caddyfile - νλ‘λμ
μ€μ μμ
# κΈλ‘λ² μ€μ
{
email admin@example.com
acme_ca https://acme-v02.api.letsencrypt.org/directory
}
# λ©μΈ μ¬μ΄νΈ - μλ HTTPS
example.com {
# μ μ νμΌ μλΉ
root * /var/www/html
file_server
# SPA λΌμ°ν
try_files {path} /index.html
# μμΆ
encode gzip zstd
# 보μ ν€λ
header {
X-Content-Type-Options nosniff
X-Frame-Options DENY
Referrer-Policy strict-origin-when-cross-origin
-Server
}
# λ‘κ·Έ
log {
output file /var/log/caddy/access.log
format json
}
}
# API 리λ²μ€ νλ‘μ
api.example.com {
reverse_proxy localhost:8080 {
health_uri /health
health_interval 10s
# λ‘λ λ°Έλ°μ± (μ¬λ¬ λ°±μλ μ)
# lb_policy round_robin
}
# CORS ν€λ
header Access-Control-Allow-Origin *
}
Senior: "If you need HTTPS in a local development environment, use Caddy. Set up mkcert and three lines of Caddyfile are all it takes."
Junior: "Can I use it in production instead of Nginx?"
Senior: "Absolutely. Automatic certificate renewal is the default, so you don't have to worry about things like a certbot cron job. That said, for very high traffic, Nginx tuning may be more familiar to you."
Interviewer: "How does Caddy's automatic HTTPS work?"
Candidate: "Caddy communicates with Let's Encrypt via the ACME protocol. It handles domain validation (HTTP-01 or DNS-01), certificate issuance, and renewal all automatically, and renews in the background before expiration. OCSP stapling is also automatic, so TLS handshake performance is good as well."
Take a mock interview on this topic β WIA SOOM AI Interview Β· Start for free
Reviewer: "I'd like the hardcoded backend address in the Caddyfile to be changed to an environment variable. It may differ by environment in Docker Compose."
Developer: "Yes, it supports environment variable placeholders like {$BACKEND_HOST}. I'll make the change."