在 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
Certbot 会自动:
Certbot 安装后默认会创建 systemd timer:
sudo systemctl status certbot.timer
手动测试续期(不真正替换证书):
sudo certbot renew --dry-run
certbot.timer 每天检查Certbot 默认会在续期成功后执行:
systemctl reload nginx
如果你用的是非标准配置,可手动指定:
sudo certbot renew --nginx
或在 /etc/letsencrypt/renewal/example.com.conf 中确认:
renew_hook = systemctl reload nginx
如果你是用 acme.sh 或其他工具:
0 3 * * * /root/.acme.sh/acme.sh --renew -d example.com --nginx
检查:
sudo journalctl -u certbot.timer
sudo certbot certificates
Let’s Encrypt 需要 80 端口
需用 DNS 验证:
certbot certonly --manual --preferred-challenges=dns -d *.example.com
✅ Debian + Nginx + Certbot
apt install certbot python3-certbot-nginx
certbot --nginx -d domain.com
无需额外配置,自动续期
如果你愿意,可以告诉我:
我可以给你更精确的命令。