在 Debian 上让 Nginx + SSL 自动续签,最常用、最省事的做法是 使用 Let’s Encrypt 的 certbot。
下面给你一套标准、稳定、可自动续签的方案。
sudo apt update
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d example.com -d www.example.com
替换
example.com为你自己的域名
证书会自动写入 Nginx 配置
sudo certbot renew --dry-run
如果没报错,说明续签机制正常。
certbot 安装后会自动创建:
certbot.timer查看状态:
systemctl status certbot.timer
如果你 不是用 --nginx 参数,而是手动配置:
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
那续签用:
sudo certbot renew
并在 Nginx 配置里加:
location /.well-known/acme-challenge/ {
root /var/www/html;
}
certbot 默认会尝试 reload Nginx:
systemctl reload nginx
如果你想更稳妥,可以加 hook:
sudo certbot renew --nginx
或在:
/etc/letsencrypt/renewal/example.com.conf
确认有:
renew_hook = systemctl reload nginx
❌ 防火墙没开 80 端口(HTTP 验证必须)
❌ DNS 没解析到服务器
❌ 用了 CDN 但没关 SSL 代理
❌ 证书目录权限被改
sudo certbot certonly --manual --preferred-challenges dns -d example.com
但 这种方式不能全自动续签,需要 DNS API 插件(如 Cloudflare)。
apt install certbot python3-certbot-nginx
certbot --nginx -d yourdomain.com
certbot renew --dry-run
✅ 全自动续签
✅ Nginx 零维护
如果你愿意,可以告诉我:
我可以给你定制方案。