【问题标题】:Reverse proxy and Socket.io, failed websocket handshake反向代理和 Socket.io,websocket 握手失败
【发布时间】:2015-01-15 00:03:37
【问题描述】:

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

来自网站(客户端浏览器)的 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://地址配置反向代理的技巧或解决方案?

【问题讨论】:

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


【解决方案1】:

我会稍微扩展一下我的 cmets。 据我了解,您有多种选择:

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

【讨论】:

    猜你喜欢
    • 2016-11-17
    • 2015-08-28
    • 2015-03-16
    • 2011-09-28
    • 1970-01-01
    • 2019-06-25
    • 1970-01-01
    • 2017-02-12
    • 1970-01-01
    相关资源
    最近更新 更多