云计算之路-阿里云上:在SLB上部署https遇到的问题及解决方法
一、问题场景
这个问题只会出现在云服务器操作系统使用Windows Server 2012的场景,如果使用的是Windows Server 2008 R2则不存在这个问题。
二、https部署场景
1. 阿里云SLB的配置:
要让SLB支持https,需要使用4层负载均衡,也就是添加TCP协议,并添加443端口。
2. Windows Server 2012云服务器中IIS的相应配置:
参考博文:给IIS添加CA证书以支持https
三、遇到的问题
以https通过SLB的VIP无法访问目标站点,而通过云服务器的公网IP可以正常访问,在其他云服务器中通过内网IP也可以正常访问。
telnet可以正常连接SLB的443端口。
四、问题的排查过程
我们向阿里云提交工单之后,阿里云技术工程师在云服务器所在的宿主机上进行了抓包测试,发现云服务器收包之后,没有回包。
我们查看IIS日志,发现日志中没有https请求的踪迹,阿里云技术工程师说这是由于TCP三次握手没完成。
图片来自:简单理解Socket
于是根据阿里云技术工程师的建议,我们在云服务器内部进行了抓包。
我们用的工具是Wireshark,抓包结果如下图:
抓包结果说明云服务器收到了来自SLB的https请求的SYN包,却没有回包。
于是问题就锁定在为什么没有回包?
我们怀疑是底层虚拟机化层面的问题,阿里云怀疑是云服务器内部Windows的问题。
五、问题的解决
阿里云技术工程师另外用Windows Server 2012部署了同样的场景,成功重现了问题,并给我们提供解决方法(解决方法链接),以下是关键步骤:
1. Install the Loopback Adapter
2. Make the Windows Networking Stack Use the Weak Host Model
netsh interface ipv4 set interface <IDX> weakhostreceive=enabled
3. Add the Loopback Adapter to your Site Bindings
但这个解决方案针对的是Windows Server 2003和2008,我们在Windows Server 2012上按照这三个步骤设置之后,问题并没有解决。但问题的原因就在这个地方,我们稍作摸索,就成功解决了问题。
下面是具体的设置步骤:
1. 安装Loopback Adapter(在Windows Server 2012中叫Microsoft KM-TEST Loopback Adapter)
- 打开Device Manager(设置管理器)
- Add legacy hardware
- Install hardware that I manually select from a list(Advanced)
- Network adapters
- Microsoft -> Microsoft KM-TEST Loopback Adapter
2. 启用Weak Host Model
- 在命令行下运行netsh interface ipv4 show interface,得到所有网络接口的Idx
- 为所有网络接口分别设置weakhostsend=enabled, weakhostsend=enabled
netsh interface ipv4 set interface 1 weakhostsend=enabled netsh interface ipv4 set interface 1 weakhostreceive=enabled netsh interface ipv4 set interface 15 weakhostsend=enabled netsh interface ipv4 set interface 15 weakhostreceive=enabled netsh interface ipv4 set interface 17 weakhostsend=enabled netsh interface ipv4 set interface 17 weakhostreceive=enabled netsh interface ipv4 set interface 29 weakhostsend=enabled netsh interface ipv4 set interface 29 weakhostreceive=enabled
3. 在IIS中添加额外的针对Loopback Adapter的https绑定
上图中的169.254.164.223就是添加的Microsoft KM-TEST Loopback Adapter网络接口自动分配的IP地址。
完成这些配置之后,问题就解决了!
六、参考资料
- Barracuda Load Balancer - Deployment in a Microsoft Windows Server 2003 or 2008 Environment
- IIS 8 NLB LoopBack Issues
七、相关链接
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· C++代码改造为UTF-8编码问题的总结
· DeepSeek 解答了困扰我五年的技术问题
· 为什么说在企业级应用开发中,后端往往是效率杀手?
· 2分钟学会 DeepSeek API,竟然比官方更好用!
· .NET 使用 DeepSeek R1 开发智能 AI 客户端
· autohue.js:让你的图片和背景融为一体,绝了!
· 10亿数据,如何做迁移?
· 推荐几款开源且免费的 .NET MAUI 组件库
2012-12-07 博客园电子期刊2012年11月刊发布啦
2011-12-07 博客园电子期刊2011年11月刊发布啦
2009-12-07 memcached罢工引发的血案-博客园评论超时问题处理过程
2009-12-07 上周热点回顾(11.30-12.6)
2009-12-07 博客园首页优化心得