证书

验证 HTTPS 证书续期

使用 certbot 配置自动续期,并验证续期后新证书已被正确加载。

更新于 2026-11-23

适用环境

  • 已通过 certbot 申请 Let’s Encrypt 证书的站点
  • 需要确认自动续期与重载服务都正常工作

操作步骤

1. 查看续期计时器

sudo systemctl list-timers certbot.timer

或确认 crontab:

sudo crontab -l | grep certbot

2. 执行一次演练

sudo certbot renew --dry-run

演练不真正签发,只验证验证方式与配置可用。

3. 配置续期后重载 Nginx

在 /etc/letsencrypt/cli.ini 或部署钩子中加入:

deploy-hook = systemctl reload nginx

验证方法

续期前后对比证书序列号与有效期:

echo | openssl s_client -connect www.example.com:443 -servername www.example.com \
  2>/dev/null | openssl x509 -noout -serial -dates

失败处理

  • DNS-01 失败:核对 DNS 验证凭据只授权给 _acme-challenge 区域,并确认 TXT 记录已生效。
  • 重载后仍用旧证书:sudo systemctl reload nginx 后再次请求,必要时清浏览器缓存。
  • 计时器未生效:sudo systemctl enable --now certbot.timer。

参考资料