【发布时间】:2016-01-21 05:53:36
【问题描述】:
我搜索了互联网,试图找到任何可能遇到此问题但空手而归的人。所以这里是:
我们有一个 java web 应用程序(基于 Spring MVC 4)。它位于 Microsoft IIS 后面,使用应用程序请求路由 (ARR) v3 充当负载平衡器/反向代理。
此 IIS 使用 ARR 为 3 个不同的环境(都运行相同 Java 代码)执行负载平衡:dev.example.com、demo.example.com 和 qa.example.com。
应用程序通过 SockJS 和 stompjs 使用 WebSockets 向用户的浏览器提供通知,当应用程序服务器在 Tomcat 7 上时,这一切都运行良好。将qa.example.com 环境升级到 Tomcat 8 后,WebSocket 连接停止工作 -它回退到 XHR POST 请求。
我想强调的是,没有对 IIS 进行任何更改,只是对 qa 应用程序服务器进行了更改。
这是来自dev 环境(工作)的示例请求/响应:
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8
Cache-Control: no-cache
Connection: Upgrade
Cookie: <cookies snipped>
Host: dev.example.com
Origin: https://dev.example.com
Pragma: no-cache
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
Sec-WebSocket-Key: E7aIek0X6qcO9PAl1n6w4Q==
Sec-WebSocket-Version: 13
Upgrade: websocket
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.71 Safari/537.36
回应
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Connection: Upgrade
Date: Thu, 22 Oct 2015 02:19:35 GMT
Expires: 0
Pragma: no-cache
Sec-WebSocket-Accept: dKYK05s4eP87iA20aSo/3ntOrPU=
Server: Microsoft-IIS/8.0
Strict-Transport-Security: max-age=31536000 ; includeSubDomains
Upgrade: Websocket
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-Powered-By: ARR/3.0
X-XSS-Protection: 1; mode=block
这是来自qa 环境的示例请求/响应(已损坏):
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8
Cache-Control: no-cache
Connection: Upgrade
Cookie: <cookies snipped>
Host: qa.example.com
Origin: https://qa.example.com
Pragma: no-cache
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
Sec-WebSocket-Key: jTOIAT0+o35+Qi0ZWh2gyQ==
Sec-WebSocket-Version: 13
Upgrade: websocket
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.71 Safari/537.36
回复:
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Connection: Upgrade
Date: Thu, 22 Oct 2015 02:18:30 GMT
Expires: 0
Pragma: no-cache
Sec-WebSocket-Accept: P+fEH8pvxcu3sEoO5fDizjSbwJc=
Sec-WebSocket-Extensions: permessage-deflate;client_max_window_bits=15
Server: Microsoft-IIS/8.0
Strict-Transport-Security: max-age=31536000 ; includeSubDomains
Upgrade: Websocket
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-Powered-By: ARR/3.0
X-XSS-Protection: 1; mode=block
唯一明显的区别是qa 响应包含Sec-WebSocket-Extensions: permessage-deflate;client_max_window_bits=15 标头,而dev 响应不包含。
我在 IIS 上打开“失败的请求跟踪”以调试 101 响应,我可以看到有一些标头被 IIS 覆盖 - 即 Sec-WebSocket-Accept 标头。
IIS 还显示该请求正在创建502.5 错误。我查了一下,发现了这个:https://support.microsoft.com/en-us/kb/943891,它说502.5 是“WebSocket 故障(ARR)”,这就是它所说的全部。奇怪的是,Chrome 开发工具显示它响应 101 就像它应该做的那样......
我使用本地应用程序服务器(没有 IIS 的 Tomcat 8)尝试了这一切,并且 websocket 工作得很好。 Tomcat 7 + IIS + ARR + WebSockets 工作得很好。 Tomcat 8 + IIS + ARR + WebSockets 没有。
我的 Tomcat 8 的确切版本是 8.0.28 - 但我在 Tomcat 8.0.26 上得到了相同的结果。
我的下一步是通过次要版本继续降级 Tomcat 8,看看是否有任何变化。如果我发现任何东西,我会在这里更新。
更新
这是来自我的本地服务器(无 IIS)的响应:
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Connection: upgrade
Date: Thu, 22 Oct 2015 13:59:23 GMT
Expires: 0
Pragma: no-cache
Sec-WebSocket-Accept: 718HnPxHN8crYYzNGFjQf7w8O+Y=
Sec-WebSocket-Extensions: permessage-deflate;client_max_window_bits=15
Server: Apache-Coyote/1.1
Strict-Transport-Security: max-age=31536000 ; includeSubDomains
Upgrade: websocket
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block
它看起来很像被破坏的qa 请求,但效果很好。所以我猜Sec-WebSocket-Extensions 的事情是一个红鲱鱼。在我的本地服务器上,Upgrade: websocket 和 Connection: upgrade 也是小写,而当您将 IIS 放在前面时,它是 Websocket 和 Upgrade。
Sec-WebSocket-Extensions 在qa 的permessage-deflate; 之后也有一个尾随空格,但本地没有。
更新 2
在 Microsoft Edge (Windows 10) 中的 qa 环境中一切正常 我没有尝试过 Internet Explorer 11,但我不得不假设它可能也可以工作。 OSX 上的 Firefox 和 Chrome 不工作。
更新 3
在 IIS/ARR 修改之前来自 Tomcat 的请求:
HTTP/1.1 101 Switching Protocols
Server: Apache-Coyote/1.1
Upgrade: websocket
Connection: upgrade
Sec-WebSocket-Accept: luP49lroNK9qTdaNNnSCLXnxAWc=
Sec-WebSocket-Extensions: permessage-deflate;client_max_window_bits=15
Date: Tue, 27 Oct 2015 21:10:48 GMT
【问题讨论】:
-
你能在 Tomcat 的 websockets 上禁用压缩吗? Sec-WebSocket-Extensions:permessage-deflate;表明它正在被压缩,以我的经验 IIS 没有代理压缩的 websocket。
-
@timmah.faase 我会试一试并报告
-
所以,我尝试将此选项添加到我的 Tomcat 配置中:
-Dorg.apache.tomcat.websocket.DISABLE_BUILTIN_EXTENSIONS=true根据文档应该可以解决问题:If true, disable all built-in extensions provided by the server, such as message compression.但它似乎没有改变响应标题
标签: java tomcat iis websocket arr