跳到正文
Virtual Roaming
返回

关于 SSL-TLS 证书过期排查

编辑页面

关于SSL-TLS 证书过期排查

1、证书过期更新

# 查看证书状态
sudo certbot certificates
# 过期
# Certificate Name: example.com
#     Domains: example.com www.example.com
#     Expiry Date: 2025-09-01 12:00:00+00:00 (INVALID: EXPIRED)
#     Certificate Path: /etc/letsencrypt/live/example.com/fullchain.pem
#     Private Key Path: /etc/letsencrypt/live/example.com/privkey.pem
# 续期
sudo certbot renew
# 成功
# Congratulations, all renewals succeeded
# 失败
# 80端口(HTTP) 和 443端口(HTTPS) 已经被其他进程占用了,导致 nginx 无法绑定这两个端口。
# 所以在 Certbot 尝试 reload nginx 的时候失败了。
# Encountered exception during recovery:
# certbot.errors.MisconfigurationError: nginx restart failed:
# nginx: [emerg] bind() to [::]:443 failed (98: Unknown error)
# nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Unknown error)
# nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Unknown error)
# nginx: [emerg] bind() to [::]:80 failed (98: Unknown error)
# 停止nginx再续期
sudo systemctl stop nginx
sudo certbot renew
sudo systemctl start nginx
sudo systemctl status nginx

2、证书过期更新nginx重启失败

1、检查服务器真实返回证书

# 远程访问端口
openssl s_client -connect domain:443 -servername domain | openssl x509 -noout -dates
#  服务器本机
echo | openssl s_client -connect 127.0.0.1:443 -servername domain | openssl x509 -noout -dates 
# notAfter=Feb 26 (旧证书 nginx未 reload)

2、检查证书文件

openssl x509 -in /etc/letsencrypt/live/domain/fullchain.pem -noout -dates # 
# notAfter=Apr 27 (新证书)

3、检查 nginx 监听端口

ss -lntp | grep :443
# 确认 nginx 是否处理 HTTPS nginx pid=xxxx
# LISTEN 0    511     0.0.0.0:443   0.0.0.0:*   users:(("nginx",pid=xxxx,fd=x),("nginx",pid=xxxx,fd=x),("nginx",pid=xxxx,fd=x))

4、检查 nginx 配置

nginx -T # 查看 nginx 实际加载配置
# ...实际配置
nginx -t # 确保 nginx 配置可用
# nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
# nginx: configuration file /etc/nginx/nginx.conf test is successful

5、尝试 reload nginx

nginx -s reload
# 如果 reload 失败检查 PID(nginx.pid 文件损坏)
cat /run/nginx.pid
# 找出当前 nginx master pid
ps -ef | grep nginx # 找到 nginx: master process ... ← 这就是 master PID
# 强制重新加载配置
kill -HUP masterPID # 生效关键点

3、为什么找 nginx: master process

4、nginx 常见信号

信号作用
HUPreload 配置
QUIT优雅停止
TERM快速停止
USR1reopen log
USR2平滑升级

编辑页面
分享本文:

上一篇
关于 nextjs DockerFile 更新
下一篇
LLM-PyTorch