温馨提示×

nginx ssl在debian如何续期

小樊
40
2026-09-05 19:52:18
栏目: 云计算

在 Debian 上,Nginx 的 SSL 证书最常见是用 Let’s Encrypt(certbot)签发的,续期方式如下。如果你用的是其他证书(商业证书),方式会不同,我也会简单说明。


一、使用 Let’s Encrypt(certbot)的情况(最常见)

1. 查看是否已安装 certbot

which certbot

certbot --version

如果没有:

sudo apt update
sudo apt install certbot python3-certbot-nginx

2. 手动测试续期(不真正替换)

sudo certbot renew --dry-run

3. 手动立即续期

sudo certbot renew

certbot 只在证书剩余 < 30 天时才会真正更新


4. 自动续期(默认已启用)

Debian 下 certbot 会自动创建:

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

查看状态:

systemctl status certbot.timer

启用(如果没开):

sudo systemctl enable --now certbot.timer

5. Nginx 重新加载证书

certbot 默认会:

  • 更新证书
  • 自动 reload nginx

如果你想手动确认:

sudo nginx -t
sudo systemctl reload nginx

二、证书路径(常见)

/etc/letsencrypt/live/域名/
├── fullchain.pem
└── privkey.pem

Nginx 配置通常类似:

ssl_certificate     /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

三、如果你用的是「商业 / 自签证书」

1. 重新生成或下载新证书

2. 替换文件(路径和上面一致)

3. 重载 Nginx

sudo nginx -t
sudo systemctl reload nginx

⚠️ 商业证书不会自动续期,需要你手动操作或写脚本。


四、常见问题

1. 续期失败(80 端口被占用)

Let’s Encrypt 需要验证:

sudo netstat -tlnp | grep ':80'

2. 证书没自动续期

sudo journalctl -u certbot.timer
sudo certbot certificates

如果你愿意,可以告诉我:

  • Debian 版本(cat /etc/os-release
  • 是否用 certbot
  • 域名或 Nginx 配置片段

我可以帮你精确检查。

0