在HAproxy中,我的websocket连接在50秒后关闭。怎么改呢?

问题描述 投票:3回答:3

我正在使用带有龙卷风的Haproxy作为websocket。如果我直接连接到龙卷风我的连接工作正常,但如果我使用HAproxy与下面的配置然后连接50秒后关闭。我的Haproxy配置文件如下。

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

    defaults
        mode http
        timeout connect 5000ms
        timeout client 50000ms
        timeout server 50000ms
        option  http-server-close
        maxconn 4032

    frontend http-in
        bind *:80
        acl is_websocket hdr_end(host) -i WebSocket
        use_backend servers if is_websocket
        default_backend servers
        option  redispatch
        option  http-server-close
        maxconn  2000
        contimeout  500000
        clitimeout  500000
        srvtimeout  500000
        contimeout  500000        
        timeout contimeout  500000 
        timeout connect  500000

    backend servers
        server server1 127.0.0.1:8886 maxconn 4032

现在通过使用上面的配置,我的websocket连接在50秒后自动丢失。我想做持久连接,所以有没有办法在HAproxy中建立连接?

websocket tornado haproxy
3个回答
6
投票

为了更好地理解HAProxy如何与websocket一起使用,您应该阅读本文:https://www.haproxy.com/blog/websockets-load-balancing-with-haproxy/

请注意关闭超时是个坏主意...

浸礼者


5
投票

我更改了超时连接0ms,超时客户端0ms,默认部分超时服务器0ms然后我的连接是持久连接,因为如果我给值0,那么它将是无限连接超时值。

您不应该这样做,因为这些选项也适用于通常的HTTP流量。将超时连接/客户端/服务器设置为适当的值,并将timeout tunnel用于websockets。

当在客户端和服务器之间建立双向连接时,隧道超时适用,并且连接在两个方向上保持不活动状态。一旦连接成为隧道,此超时将取代客户端和服务器超时。

(见:http://cbonte.github.io/haproxy-dconv/configuration-1.5.html#timeout%20tunnel


2
投票

我找到了回答,

我在timeout connect 0ms, timeout client 0ms, timeout server 0ms部分更改了defaults然后我的连接是持久连接,因为如果我给值0那么它将是无限连接超时值。

我的最终工作配置如下,

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

    defaults
        mode http
        timeout connect 0ms
        timeout client 0ms
        timeout server 0ms
        option  http-server-close
        maxconn 4032

    frontend http-in
        bind *:80
        acl is_websocket hdr_end(host) -i WebSocket
        use_backend servers if is_websocket
        default_backend servers
        option  redispatch
        option  http-server-close
        maxconn  2000
        contimeout  500000
        clitimeout  500000
        srvtimeout  500000
        contimeout  500000        
        timeout contimeout  500000 
        timeout connect  500000
        timeout client  500000

    backend servers
        server server1 127.0.0.1:8886 maxconn 4032
© www.soinside.com 2019 - 2024. All rights reserved.