在 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为你自己的域名
✅ Certbot 会:
Congratulations! You have successfully enabled HTTPS.
Debian 安装后,Certbot 会自动创建:
systemctl status certbot.timer
应该看到:
Active: active (waiting)
systemctl list-timers | grep certbot
sudo certbot renew --dry-run
✅ 没有报错说明自动续期配置正确
证书通常位于:
/etc/letsencrypt/live/example.com/
包含:
cert.pem
chain.pem
fullchain.pem
privkey.pem
Nginx 示例配置:
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
Certbot 会在续期成功后自动执行:
nginx -s reload
如果你手动修改了证书,可以执行:
sudo nginx -t
sudo systemctl reload nginx
sudo ufw allow 443/tcp
sudo ufw allow 80/tcp
查看日志:
sudo journalctl -u certbot
或:
sudo cat /var/log/letsencrypt/letsencrypt.log
sudo certbot certonly --manual --preferred-challenges dns -d example.com
⚠️ 需手动添加 TXT DNS 记录(不方便自动续期)
apt update
apt install certbot python3-certbot-nginx
certbot --nginx -d example.com
certbot renew --dry-run
✅ 证书 90 天有效期
✅ 自动续期无需人工干预
如果你愿意,我可以:
直接把你的 系统版本 + 域名 + Nginx 配置 发我即可。