openssl 连接失败的原因很多,必须结合具体错误信息才能精确定位。下面我按最常见原因 → 排查方法 → 示例来说明,你可以对照看看属于哪一种。
| 现象 | 可能原因 |
|---|---|
connect: Connection refused |
服务没启动 / 端口不对 |
No route to host |
IP 不可达 / 防火墙 |
Connection timed out |
网络不通 / 防火墙 |
unknown protocol |
端口不是 SSL/TLS |
alert handshake failure |
协议或加密套件不匹配 |
certificate verify failed |
证书校验失败 |
wrong version number |
用错协议(如 HTTPS 连 HTTP) |
SSL23_GET_SERVER_HELLO |
服务端不是 TLS |
openssl s_client -connect example.com:443
错误:
connect: Connection refused
✅ 排查:
ss -lntp | grep 443
netstat -tulnp | grep 443
原因:
connect: Connection timed out
✅ 排查:
ping example.com
telnet example.com 443
原因:
openssl s_client -connect example.com:80
错误:
wrong version number
✅ 原因:
✅ 解决:
openssl s_client -connect example.com:443
openssl s_client -connect example.com:443 -verify 5
错误:
Verify return code: 21 (unable to verify the first certificate)
✅ 原因:
✅ 临时绕过(不推荐生产):
openssl s_client -connect example.com:443 -verify 0
handshake failure
✅ 原因:
✅ 尝试:
openssl s_client -connect example.com:443 -tls1_2
openssl s_client -connect example.com:443 -tls1_3
openssl s_client -connect 1.2.3.4:443
✅ 解决:
openssl s_client -connect example.com:443
ss -lntp
ping host
telnet host port
openssl s_client -connect host:port -debug
请把完整错误信息贴出来,例如:
openssl s_client -connect xxx:443
CONNECTED(00000003)
...
或者直接告诉我:
我可以一步一步帮你查到根因 ✅