HAProxy + WebSocket断开连接 [英] HAProxy + WebSocket Disconnection

查看:644
本文介绍了HAProxy + WebSocket断开连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用HAProxy在子域上将请求发送到node.js应用程序.

I am using HAProxy to send requests, on a subdomain, to a node.js app.

我无法使WebSockets正常工作.到目前为止,我只能让客户端建立WebSocket连接,但是之后很快就会断开连接.

I am unable to get WebSockets to work. So far I have only been able to get the client to establish a WebSocket connection but then there is a disconnection which follows very soon after.

我在ubuntu上.我一直在使用socket.ionode-websocket-server的各种版本.客户端是Safari或Chrome的最新版本. HAProxy版本是1.4.8

I am on ubuntu. I have been using various versions of socket.io and node-websocket-server. The client is either the latest versions of Safari or Chrome. HAProxy version is 1.4.8

这是我的HAProxy.cfg

Here is my HAProxy.cfg

global 
    maxconn 4096 
    pidfile /var/run/haproxy.pid 
    daemon 

defaults 
    mode http 

    maxconn 2000 

    option http-server-close
    option http-pretend-keepalive

    contimeout      5000
    clitimeout      50000
    srvtimeout      50000

frontend HTTP_PROXY
    bind *:80 

    timeout client  86400000

    #default server
    default_backend NGINX_SERVERS

    #node server
    acl host_node_sockettest hdr_beg(host) -i mysubdomain.mydomain

use_backend NODE_SOCKETTEST_SERVERS if host_node_sockettest


backend NGINX_SERVERS 
server THIS_NGINX_SERVER 127.0.0.1:8081

backend NODE_SOCKETTEST_SERVERS
timeout queue   5000
timeout server  86400000

server THIS_NODE_SERVER localhost:8180 maxconn 200 check

我已经拖曳了网络和邮件列表,但无法获得任何建议的解决方案.

I've trawled the web and mailing list but can not get any of the suggested solutions to work.

(请注意,这可能是服务器故障,但是S.O上还有其他HAProxy问题,所以我选择在此处发布)

(p.s. this could be for serverfault, but there are other HAProxy question on S.O, so I have chosen to post here)

推荐答案

升级到最新版本的socket.io(0.6.8-> npm install socket.io@0.6.8,已修补为与HAProxy一起使用) 并下载最新版本的HAProxy.

Upgrade to latest version of socket.io (0.6.8 -> npm install socket.io@0.6.8, which is patched to work with HAProxy) and download the latest version of HAProxy.

这是一个示例配置文件:

Here is an example config file:

global
    maxconn     4096 # Total Max Connections. This is dependent on ulimit
    nbproc      2

defaults
    mode        http

frontend all 0.0.0.0:80
    timeout client 5000
    default_backend www_backend
    acl is_websocket hdr(Upgrade) -i WebSocket
    acl is_websocket hdr_beg(Host) -i ws

    use_backend socket_backend if is_websocket

backend www_backend
    balance roundrobin
    option forwardfor # This sets X-Forwarded-For
    timeout server 5000
    timeout connect 4000
    server server1 localhost:8081 weight 1 maxconn 1024 check
    server server2 localhost:8082 weight 1 maxconn 1024 check
    server server3 localhost:8083 weight 1 maxconn 1024 check

backend socket_backend
    balance roundrobin
    option forwardfor # This sets X-Forwarded-For
    timeout queue 5000
    timeout server 5000
    timeout connect 5000
    server server1 localhost:8081 weight 1 maxconn 1024 check
    server server2 localhost:8082 weight 1 maxconn 1024 check
    server server3 localhost:8083 weight 1 maxconn 1024 check

这篇关于HAProxy + WebSocket断开连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆