我有Ubuntu 12.04LTS运行。 我的networking服务器是Tomcat 7.0.42,我使用HAProxy作为代理服务器。 我的应用程序是一个使用websockets的servlet应用程序。
有时候,当我要求我的网页,我得到“502错误的网关”错误在一些资源不是所有,但在一些。 我认为这与我的HAProxyconfiguration有关,如下所示:
global maxconn 4096 # Total Max Connections. This is dependent on ulimit nbproc 1 defaults mode http option http-server-close option httpclose # option redispatch no option checkcache # test against 502 error frontend all 0.0.0.0:80 timeout client 86400000 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 30000 timeout connect 4000 server apiserver localhost:8080 weight 1 maxconn 1024 check backend socket_backend balance roundrobin option forwardfor # This sets X-Forwarded-For timeout queue 5000 timeout server 86400000 timeout connect 86400000 server apiserver localhost:8080 weight 1 maxconn 1024 check
我有什么要改变,以防止502错误?
首先,启用haproxy日志记录。 它只会告诉你为什么给502。 我的猜测是,后端“本地主机:8080”根本无法跟上或无法获得连接4000毫秒“超时连接4000”。
您可能已经超出了HAProxy中的一些默认限制。 尝试将以下内容添加到全局部分:
tune.maxrewrite 4096 tune.http.maxhdr 202