“Nginx 很强,但越来越多人开始把生产环境切到 Caddy。”
过去十几年,Nginx 几乎是 Web Server、反向代理、静态资源服务器的标准答案。 但随着 HTTPS 普及、容器化部署、自动化运维和微服务的发展,Nginx 的一些“老派设计”开始暴露问题:
而这时候,一个新选手开始崛起:
它被很多开发者称为:
“现代化版 Nginx”

一句话总结:
Caddy 默认就做对了很多事。
它不像传统 Web Server:
而 Caddy:
你甚至只需要:
example.com {
reverse_proxy localhost:8080
}就已经:
这在 Nginx 里,通常需要几十行配置。
先看看传统 Nginx 配置:
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://127.0.0.1:8080;
}
}接下来你还得:
真正生产环境往往会变成:
server {
listen 443 ssl http2;
server_name example.com;
ssl_certificate ...
ssl_certificate_key ...
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ...
location / {
proxy_pass ...
}
}配置越来越长。
尤其:
这是 Caddy 最大的核心竞争力。
只要域名解析正确:
example.com {
reverse_proxy localhost:8080
}启动后:
你甚至不需要知道:
对个人开发者、小团队来说:
这几乎直接减少了 80% 运维成本。
Nginx:
location /api/ {
proxy_pass http://127.0.0.1:9000;
}Caddy:
handle /api/* {
reverse_proxy localhost:9000
}更加接近自然语言。
Nginx:
nginx -s reload如果配置错误:
而 Caddy:
caddy reload具备:
对高并发系统非常友好。
现在很多人还在手动给 Nginx 编译 QUIC 模块。
但 Caddy:
默认支持 HTTP/3。
这是现代协议栈的重要优势。
Nginx Docker 常见问题:
而 Caddy:
services:
caddy:
image: caddy
ports:
- 80:80
- 443:443
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile
- caddy_data:/data结束。
证书自动存储。
不用再维护 certbot。
Linux:
curl -1sLf \
'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' \
| sudo gpg --dearmor \
-o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf \
'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' \
| sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install caddy官方文档:
原 Nginx:
server {
listen 80;
server_name api.example.com;
location / {
proxy_pass http://127.0.0.1:8080;
}
}改成 Caddy:
api.example.com {
reverse_proxy localhost:8080
}就结束了。
example.com {
root * /var/www/html
file_server
}支持:
默认就很好。
以前 Nginx:
try_files $uri /index.html;Caddy:
example.com {
root * /app/dist
try_files {path} /index.html
file_server
}非常直观。
Nginx:
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";Caddy:
根本不用写。
自动支持。
example.com {
handle /api/* {
reverse_proxy localhost:8080
}
handle /admin/* {
reverse_proxy localhost:9000
}
handle {
root * /web
file_server
}
}这已经很像 API Gateway 了。
admin.example.com {
basicauth {
admin $2a$14$xxxxxxxx
}
reverse_proxy localhost:8080
}生成密码:
caddy hash-passwordCaddy 内部实现了:
ACME 协议客户端。
流程:
域名解析
↓
ACME 验证
↓
自动签发证书
↓
自动安装
↓
自动续期整个过程完全自动化。
当然,Caddy 也不是完美的。
Nginx 十几年积累:
Caddy 生态仍小很多。
比如:
Nginx 资料压倒性更多。
很多公司:
迁移需要成本。
很多人误以为:
“Go 写的 Web Server 会比 C 差。”
实际上:
Caddy 性能非常强。
在多数业务场景:
真正瓶颈通常不在 Web Server。
而在:
最推荐。
因为:
非常舒服。
尤其:
Caddy 做:
体验很好。
尤其:
Caddy 非常强。
例如:
Nginx 仍更成熟。
某些:
仍可能优先 Nginx。
很多人用了 Caddy 后最大的感受是:
“终于不用折腾 HTTPS 了。”
以前:
都很常见。
现在:
Caddy 默认帮你搞定。
这其实是它真正改变行业的地方:
Web Server 开始“默认安全”。
个人/中小团队非常推荐:
Internet
↓
Caddy
↓
FastAPI / Node.js / Go或者:
Cloudflare
↓
Caddy
↓
Docker Services非常现代化。
如果一句话总结:
场景 | 推荐 |
|---|---|
新项目 | Caddy |
小团队 | Caddy |
Docker 化 | Caddy |
自动 HTTPS | Caddy |
超复杂企业系统 | Nginx |
OpenResty/Lua | Nginx |