在 Linux 上可以用 OpenSSL 来测试 HTTPS 服务是否正常、证书是否有效、TLS 握手是否成功。下面按常见使用场景给你列出方法和示例。
openssl s_client -connect example.com:443
✅ 如果成功,你会看到:
按 Ctrl+C 或输入 Q 退出。
现代 HTTPS 站点基本都需要 SNI:
openssl s_client -connect example.com:443 -servername example.com
如果不加
-servername,很多 CDN / 虚拟主机返回错误证书。
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -text
常用查看项:
openssl x509 -noout -subject
openssl x509 -noout -issuer
openssl x509 -noout -dates
openssl x509 -noout -text
openssl s_client -connect example.com:443 -tls1_2
openssl s_client -connect example.com:443 -tls1_3
openssl s_client -connect example.com:443 -tls1
openssl s_client -connect example.com:443 -tls1_1
openssl s_client -connect example.com:8443
echo -e "GET / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n\r\n" | \
openssl s_client -connect example.com:443 -servername example.com
✅ 适合验证:
echo | openssl s_client -connect example.com:443 2>/dev/null | openssl x509 -noout -dates
示例输出:
notBefore=May 20 00:00:00 2024 GMT
notAfter=May 20 23:59:59 2025 GMT
openssl s_client -connect example.com:443 -showcerts
你可以看到:
openssl s_client -connect 127.0.0.1:443 -servername example.com
verify error:num=62:Hostname mismatch
✅ 加 -servername
connect: Connection refused
✅ 检查端口、防火墙、服务是否启动
handshake failure
✅ 尝试不同 -tls1_2 / -tls1_3
# 基本测试
openssl s_client -connect example.com:443 -servername example.com
# 查看证书
openssl s_client -connect example.com:443 -servername example.com | openssl x509 -noout -text
如果你愿意,可以告诉我:
我可以给你更精确的测试命令和排错方案。