如何使用 Caddy 部署 HTTPS 服务
📅 2026-02-20 | ⏱️ 5分钟 | 👁 847 次阅读 | 💬 10 条评论
前言
Caddy 是现代化的 Web 服务器,最大特点是自动 HTTPS。相比 Nginx 配置更简单,本文记录完整部署过程。
一、安装 Caddy
sudo apt update
sudo apt install caddy
sudo systemctl enable --now caddy
二、基础配置
example.com {
root * /var/www/html
file_server
encode gzip
}
三、高级配置
添加安全响应头和 HTTP/3 支持:
example.com {
root * /var/www/html
file_server
encode gzip zstd
header {
Strict-Transport-Security "max-age=31536000;"
X-Content-Type-Options "nosniff"
X-Frame-Options "SAMEORIGIN"
}
# HTTP/3 默认启用
protocols h1 h2 h3
}
四、重启服务
sudo systemctl restart caddy
sudo systemctl status caddy
💡 提示:Caddy 会自动申请和续期 Let's Encrypt 证书,无需手动配置。
💬 评论 (10)
发表评论
⚠️ 评论功能即将上线,敬请期待