在 Linux 下使用 OpenSSL 时,排查错误通常可以从命令返回信息、错误码、日志、配置、证书本身几个层面入手。下面给你一套实用的排查思路和常见方法。
OpenSSL 命令失败通常会直接打印错误,例如:
openssl s_client -connect example.com:443
常见错误:
connect: Connection refused → 网络/端口问题SSL routines:SSL23_GET_SERVER_HELLO: → 协议/加密套件不匹配certificate verify failed → 证书校验失败openssl errstr 解析错误码OpenSSL 有时会输出类似:
error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed
可以用:
openssl errstr 1416F086
输出示例:
error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed
telnet example.com 443
# 或
nc -vz example.com 443
不通的情况:
openssl s_client -connect example.com:443 -debug
或:
openssl s_client -connect example.com:443 -state
重点看:
openssl verify -CAfile ca.pem server.crt
常见错误:
unable to get local issuer certificate → 缺少 CAcertificate has expired → 证书过期hostname mismatch → 域名不匹配openssl x509 -in server.crt -noout -text
重点检查:
Not Before / Not AfterSubject / SANIssueropenssl x509 -noout -modulus -in server.crt | openssl md5
openssl rsa -noout -modulus -in server.key | openssl md5
两个 md5 必须一致。
openssl s_client -connect example.com:443 -tls1_2
openssl s_client -connect example.com:443 -tls1_3
openssl ciphers -v
openssl version
不同版本对 TLS / 算法支持不同(尤其是 1.0.2 / 1.1.1 / 3.0)。
路径通常是:
/etc/ssl/openssl.cnf
常见问题:
journalctl -u nginx
# 或
tail -f /var/log/syslog
ls /etc/ssl/certs/
更新 CA:
update-ca-certificates
| 错误 | 原因 |
|---|---|
| certificate verify failed | CA 缺失 / 证书链不完整 |
| unknown protocol | 端口不是 HTTPS |
| no shared cipher | 加密套件不匹配 |
| self signed certificate | 自签名未信任 |
| SSL23_GET_SERVER_HELLO | 协议版本不兼容 |
如果你有具体的 OpenSSL 命令和报错信息,可以直接贴出来,我可以帮你逐行分析。