解决:http: TLS handshake error from *

作者阿里云代理 文章分类 分类:linux图文教程 阅读次数 已被围观 369

目录

  • 问题
  • 解决
  • 结尾

问题

今天以容器的形式在公网上一个部署了一个云服务,在测试环境是没有问题的,不知道为什么部署到 beta 环境就出现了问题,导致 https 协议文件访问失败。

具体报错信息如下:

2021/11/09 07:15:58 http: TLS handshake error from 125.64.94.138:34428: remote error: tls: bad certificate\ 2021/11/09 07:15:58 http: TLS handshake error from 125.64.94.138:36510: EOF\ 2021/11/09 07:15:58 http: TLS handshake error from 125.64.94.138:39042: read tcp 172.17.0.79:9443->125.64.94.138:39042: read: connection reset by peer\ 2021/11/09 07:15:58 http: TLS handshake error from 125.64.94.138:41490: EOF\ 2021/11/09 07:15:58 http: TLS handshake error from 125.64.94.138:42006: read tcp 172.17.0.79:9443->125.64.94.138:42006: read: connection reset by peer\ 2021/11/09 07:16:00 http: TLS handshake error from 125.64.94.138:42738: read tcp 172.17.0.79:9443->125.64.94.138:42738: read: connection reset by peer\ 2021/11/09 07:16:01 http: TLS handshake error from 125.64.94.138:51154: read tcp 172.17.0.79:9443->125.64.94.138:51154: read: connection reset by peer\ 2021/11/09 07:16:01 http: TLS handshake error from 125.64.94.138:33806: read tcp 172.17.0.79:9443->125.64.94.138:33806: read: connection reset by peer\ 2021/11/09 07:16:01 http: TLS handshake error from 125.64.94.138:34836: read tcp 172.17.0.79:9443->125.64.94.138:34836: read: connection reset by peer\ 2021/11/09 07:16:01 http: TLS handshake error from 125.64.94.138:35318: read tcp 172.17.0.79:9443->125.64.94.138:35318: read: connection reset by peer\ 2021/11/09 07:16:16 http: TLS handshake error from 125.64.94.138:34338: read tcp 172.17.0.79:9443->125.64.94.138:34338: read: connection reset by peer\ 2021/11/09 11:24:42 http: TLS handshake error from 209.17.97.114:65306: EOF\ 2021/11/09 13:46:06 http: TLS handshake error from 89.248.174.193:39762: EOF\ 2021/11/09 15:51:50 http: TLS handshake error from 165.227.163.245:38494: EOF

通过报错信息,大致猜测可能是证书原因导致的握手失败,具体原因还不是很清楚,至少是一个分析和思考的方向。

进一步分析报错日志,可以发现握手过程中,IP 地址为 125.64.94.138 的机器不断尝试切换其他端口,但是每次都被重置连接,最终导致连接失败。

解决

网上搜索了很多资料,但是介绍的方法都没有解决自己遇到的问题,后来在梳理整体流程的时候发现了原因。因为容器服务本身同时支持 http 协议和 https 协议,有一层 https 证书,在测试环境中没有问题,但是 beta 环境中所有服务访问的入口都要经过 Nginx 代理服务转发请求,而 Nginx 服务本身又设置了一层 https 证书,二层证书不一致导致了错误的发生。

因此,解决方法有两种,一是仅使用一层 https 证书;二是统一两层证书,使用相同的签名证书。

结尾

有时候,很多问题在自测的时候很难发现,是因为没有放到具体的生产环境中去,因此,开发过程中一定要考虑到未来部署后可能出现的问题,编码时尽量规避。

本公司销售:阿里云、腾讯云、百度云、天翼云、金山大米云、金山企业云盘!可签订合同,开具发票。

我有话说: