在CentOS 7 Linux上,我成功地使用HAProxy 1.5.14在Jetty 9之前,通过FastCGI为Wordpress网站提供服务 。
它工作得很好,但是对于在同一网站上的HTML5 / WebSocket游戏,需要更高的WebSocket连接到/ws/ URL的客户端和服务器超时。
所以我修改/etc/haproxy/haproxy.cfg文件到以下内容:
global chroot /var/lib/haproxy pidfile /var/run/haproxy.pid maxconn 4000 user haproxy group haproxy daemon tune.ssl.default-dh-param 2048 defaults mode http log global option httplog option dontlognull option http-server-close option forwardfor except 127.0.0.0/8 option redispatch retries 3 timeout http-request 10s timeout queue 1m timeout connect 10s timeout client 1m # HOW TO INCREASE FOR /ws/ ? timeout server 1m # HOW TO INCREASE FOR /ws/ ? timeout http-keep-alive 10s timeout check 10s maxconn 3000 frontend public bind 144.76.184.151:80 bind 144.76.184.151:443 ssl crt /etc/pki/tls/certs/slova.de.pem acl websocket_url path_end /ws/ #timeout client 60m if websocket_url # SYNTAX ERROR use_backend ws-jetty if websocket_url default_backend jetty backend jetty server domain 127.0.0.1:8080 send-proxy backend ws-jetty timeout client 60m # IS IGNORED HERE timeout server 60m server domain 127.0.0.1:8080 send-proxy
当我设置
timeout client 60m timeout server 60m
在defaults部分,我的WebSocket游戏根据需要工作,但我不希望有1小时的超时通常的HTTP连接。
当我把该部分放入backend ws-jetty会显示警告,该超时客户端不是后端选项,因此被忽略。
当我尝试行timeout client 60m if websocket_url然后语法错误报告。
如果一些长时间的会话与短暂的会话混合在一起(例如:WebSocket和HTTP),值得考虑
timeout tunnel,它覆盖timeout client和timeout server的隧道,以及为半closures连接timeout client-fin。http://cbonte.github.io/haproxy-dconv/configuration-1.5.html#4.2-timeout%20client
当连接上的timeout tunnel处于活动状态时 – 自动为Web套接字发生,因为一旦连接升级到Web套接字,HTTP逻辑就会被分离 – 其他大部分超时都不会再为该连接触发。
请注意,这是一个空闲计时器,而不是一个会话计时器。 计时器由来自任一方向的stream量复位。 您可以将其应用于后端或默认部分。 只有在适当的时候才能被HAProxy实际使用,但是在需要的时候将其放在特定的后端可以说是最好的做法。