反向代理和Socket.io,websocket握手失败

时间:2014-11-17 22:52:46

标签: node.js sockets socket.io iis-7.5 reverse-proxy

我在Windows Server 2008 R2上使用IIS 7.5运行一个小网站。 我有一个node.js应用程序也在端口3000上运行。

来自网站(客户端浏览器)的Http调用从http://example.com/node/whatever反向代理到http://localhost:3000/whatever。到目前为止一切正常。

问题是我尝试使用socket.io。

我收到了:

    WebSocket connection to 'ws://example.com/socket.io/?EIO=3&transport=websocket&sid=adb9WRpoMFYRoS0vAAAB' 
failed: Error during WebSocket handshake: Unexpected response code: 502 

我很确定,如果我没错,那就是:

它确实将初始请求转发给我的服务器,因为对websocket服务器的初始请求是标准HTTP请求(带有一些额外的标头)。 IIS确实知道这一点并简单地转发请求。但是,在接收到websocket请求时,websocket服务器发送101响应并切换到websocket模式。 IIS无法理解websocket流量,也无法代理。

是否有为ws://地址配置反向代理的技巧或解决方案?

1 个答案:

答案 0 :(得分:0)

我会对我的评论进行一些扩展。 据我了解,您有几种选择:

那么,您使用的是哪个版本的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'
]);