简体   繁体   English

node-http-proxy websocket超时与Socket.io

[英]node-http-proxy websocket timeout with Socket.io

For some reason http-proxy causes socket.io based websocket connection reconnect after every 2 minutes. 由于某种原因,http-proxy导致每2分钟后基于socket.io的websocket连接重新连接。 Before reconnection messages are working just fine between client and server. 在重新连接之前,消息在客户端和服务器之间正常工作。 If I bypass proxy, the websocket connection works without reconnections. 如果我绕过代理,websocket连接无需重新连接即可运行。 Proxy configuration is very basic and follows an example from nodejitsu. 代理配置非常基础,并遵循nodejitsu的示例。

var http = require('http'),
  httpProxy = require('http-proxy');

var options = {
  hostNameOnly: true,
  router: {
    'example.com/sockets/': '127.0.0.1:9001'
  }
};

var proxyServer = httpProxy.createServer(options);
proxyServer.listen(80);

I have also tried to change the timeout option in configuration but this does not have an affect to the reconnection problem. 我也尝试在配置中更改超时选项,但这对重新连接问题没有影响。

timeout: 120000 // override the default 2 minute http socket timeout value in milliseconds

Software versions: Ubuntu 12.04 server, node.js 0.8.16, http-proxy 0.8.7, socket.io 0.8.7. 软件版本:Ubuntu 12.04服务器,node.js 0.8.16,http-proxy 0.8.7,socket.io 0.8.7。

This works perfectly on dev Mac (10.8.3) and on Ubuntu desktop 12.04 (virtualbox) but not on server. 这适用于开发Mac(10.8.3)和Ubuntu桌面12.04(虚拟机),但不适用于服务器。

Set the timeout in options which you are passing to createServer. 在要传递给createServer的选项中设置超时。 options.timeout for socket timeout and options.proxyTimeout to allow outgoing socket to timeout so that we could show an error page at the initial request. socket.timeout用于套接字超时, options.proxyTimeout允许传出套接字超时,以便我们可以在初始请求时显示错误页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM