如何检查 SSL 证书是否过期
2025-05-19
1
参考资料
如何检查 SSL 证书是否过期
详细说明介绍
SSL 证书过期会导致网站无法访问或浏览器警告。检查证书过期时间可提前续期,避免服务中断。
适用操作系统
Linux/Unix
Windows
macOS
证书有效性检查方法
OpenSSL 命令(Linux/macOS)
openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -dates
输出示例:
notBefore=Jan 1 00:00:00 2023 GMT notAfter=Dec 31 23:59:59 2023 GMT
PowerShell(Windows)
$cert = [System.Net.Security.SslStream]::new([System.Net.Sockets.TcpClient]::new("example.com", 443).GetStream()).RemoteCertificate $cert.GetExpirationDateString()
浏览器检查
Chrome/Firefox: 点击地址栏锁图标 → "证书" → 查看有效期
配置示例(自动监控脚本)
#!/bin/bash end_date=$(openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -enddate | cut -d= -f2) expiry_epoch=$(date -d "$end_date" +%s) current_epoch=$(date +%s) days_left=$(( (expiry_epoch - current_epoch) / 86400 )) echo "证书剩余天数: $days_left"
调试与验证
使用
openssl s_client -showcerts
查看完整证书链在线工具验证:SSL Labs (https://www.ssllabs.com/ssltest/)
注意事项
时区问题:证书时间以 GMT 为准
证书链完整性:需检查中间证书是否过期
提前续期:建议在到期前 30 天处理
多域名检查:SAN 证书需验证所有域名
服务重启:更新证书后需重启 Web 服务(如 Nginx/Apache)
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。