温馨提示×

debian中nginxssl如何续期

小樊
59
2026-10-08 14:11:40
栏目: 云计算

在 Debian 中,Nginx 使用的 SSL 证书续期方式取决于你是怎么申请的证书。下面按常见情况说明。


一、使用 Let’s Encrypt(certbot)最常见 ✅

1. 检查是否使用 certbot

which certbot
certbot certificates

如果能看到证书列表,说明是用 certbot 管理的。

2. 手动续期(测试)

sudo certbot renew --dry-run

3. 正式续期

sudo certbot renew

4. 自动续期(默认已配置)

Debian 下 certbot 通常会创建:

  • /etc/cron.d/certbot
  • 或 systemd timer:certbot.timer

查看状态:

systemctl status certbot.timer

启用(如未启用):

sudo systemctl enable --now certbot.timer

5. Nginx 重新加载

certbot 一般会自动 reload nginx,如未生效:

sudo systemctl reload nginx

二、使用 acme.sh(常见于宝塔/手动)

1. 查看证书

~/.acme.sh/acme.sh --list

2. 手动续期

~/.acme.sh/acme.sh --renew -d example.com

3. 强制续期

~/.acme.sh/acme.sh --renew -d example.com --force

4. 自动续期

acme.sh 默认会写 cron:

crontab -l

三、自签证书(非自动续期)⚠️

自签证书无法自动续期,只能重新生成:

openssl req -x509 -newkey rsa:2048 \
-keyout /etc/nginx/ssl/example.key \
-out /etc/nginx/ssl/example.crt \
-days 365 -nodes

然后:

sudo systemctl reload nginx

四、续期后 Nginx 不生效的常见原因

  1. 证书路径写死在 nginx 配置里但续期后没 reload
  2. 使用了旧证书(如拷贝到别处)
  3. 证书链不完整

检查:

nginx -t
systemctl reload nginx

五、推荐做法(最佳实践)

✅ 使用 Let’s Encrypt + certbot
✅ 不要手动复制证书文件
✅ 让 certbot 自动管理 nginx 配置

如果你愿意,可以贴一下:

  • nginx -V
  • 证书是怎么申请的
  • /etc/nginx/sites-enabled/ 配置

我可以帮你精确判断该怎么续期。

0 踩