一、問題場景
這個問題只會出現在云服務器操作系統使用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
七、相關鏈接
文章列表