反向代理和Socket.io,失败的WebSocket握手
我运行Windows Server 2008 R2上使用IIS 7.5的一个小网站。我有一个Node.js应用程式过于端口3000上运行。
HTTP从网站(客户端浏览器)调用的反向代理从到
http://localhost:3000/whatever
。一切工作正常为止。
问题是,当我尝试使用socket.io。
我收到:
WebSocket connection to 'ws://example/socket.io/?EIO=3&transport=websocket&sid=adb9WRpoMFYRoS0vAAAB'
failed: Error during WebSocket handshake: Unexpected response code: 502
我敢肯定,如果我没有错,认为:
它转发到我的服务器的初始请求作为到WebSocket服务器的初始请求是标准的HTTP请求(具有一些额外的标头)。 IIS不知道这件事,只是转发请求。然而,在接收到的WebSocket请求网页套接字服务器发送一个响应101和切换到的WebSocket模式。 IIS不理解WebSocket的流量,它是不能代理这一点。
有没有什么窍门或解决方案以配置WS反向代理://不会忽略?
回答如下:我会扩大我的意见了一下。据我了解,你有几种选择:
- 绕过连接后的反向代理(丑陋的黑客攻击,如果你问我):http://www.guyellisrocks/2014/06/using-websockets-when-your-reverse.html
- 升级到最新版本,支持本地的WebSockets EVERSE-代理。看到这个related serverfault thread这technet features announcement
- 力插座-IO不升级到WebSockets的Socket.io(后V1.0)应该已经处理,我认为,这是它应该留在彗星/长轮询,如果WebSocket的握手不工作不升级。但是,你可以强制手动反正。
所以,这socket.io的版本,您使用的?参见允许传输(下面提取)的docs:
io.enable('browser client minification'); // send minified client
io.enable('browser client etag'); // apply etag caching logic based on version number
io.enable('browser client gzip'); // gzip the file
io.set('log level', 1); // reduce logging
// enable all transports (optional if you want flashsocket support, please note that some hosting
// providers do not allow you to create servers that listen on a port different than 80 or their
// default port)
io.set('transports', [
'websocket'
, 'flashsocket'
, 'htmlfile'
, 'xhr-polling'
, 'jsonp-polling'
]);