Let’s Encrypt 证书没有正常续期的问题排查和解决

2025-08-12

今天正常访问 测试牛 的时候,发现访问异常了,提示访问的链接不是专用链接,如下图:

20250812112408-7805508030.png

看起来就是 https 证书出了问题,查看证书详情,果然是因为证书过期了,如下图:

20250812112348-4175229819.png

可是我明明设置了证书自动续期来着,为啥没生效么?开始排查。

首先,SSH 到控制台,执行命令

sudo certbot renew --dry-run

尝试进行手动更新证书。

这时候控制台输出

Another instance of Certbot is already running.

看起来是上次自动续期的命令卡住了。

继续执行命令

ps aux | grep '[c]ertbot'

查看输出结果中果然有没有退出的 certbot 在运行。

root 995 0.0 0.0 113284 1392 ? Ss Jul13 0:00 /bin/sh -c test -x /usr/bin/certbot && perl -e 'sleep int(rand(3600))' && certbot -q renew --renew-hook "systemctl reload nginx"

root 1876 0.0 1.7 269360 31608 ? S Jul13 0:00 /usr/bin/python2 /usr/bin/certbot -q renew --renew-hook systemctl reload nginx

执行命令

sudo kill 995sudo kill 1876

把这两个进程都给退出了。

终于可以执行证书更新命令了

sudo certbot renew --dry-run

这次跑起来,也没报错了。

当我兴冲冲的跑去刷新页面的时候,还是傻眼了,问题依然存在。

然后 GPT 告诉我,可以去服务器查看下证书是不是真的更新了,命令是

openssl x509 -in /etc/letsencrypt/live/域名/fullchain.pem -noout -dates

果然,事出必有因,证书竟然真的没有更新,返回的时间和截图的一样:

notBefore=May 13 15:24:35 2025 GMT

notAfter=Aug 11 15:24:34 2025 GMT

我又把自动续期的 crontab 脚本扒出来,把里面的续期命令拿出来单独执行了一下

certbot -q renew --renew-hook "systemctl reload nginx"

再回去刷新页面,问题解决,完美。

总结下,按下面流程来执行命令就可以解决问题:

1、执行ps aux | grep '[c]ertbot'检查是否存在 certbot 相关进程,如果有,就给结束掉;

2、执行certbot -q renew --renew-hook "systemctl reload nginx" 强制更新证书,并重启 nginx 服务;

3、执行openssl x509 -in /etc/letsencrypt/live/域名/fullchain.pem -noout -dates 检查证书有效期是否更新正确;

以上,希望对你也有帮助。

#测试运维 1

1
收藏
已读
分享
X