我运行的是 Ubuntu 12.04LTS。我的网络服务器是 Tomcat 7.0.42,我使用 HAProxy 作为代理服务器。我的应用程序是一个使用 websockets 的 servlet 应用程序。
有时,当我请求我的页面时,我在某些资源上收到“502 Bad Gateway”错误,但不是在所有资源上,而是在某些资源上。我认为这与我的 HAProxy 配置有关,如下所示:
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。我的猜测是后端“localhost:8080”根本无法跟上或无法在 4000 毫秒“timeout connect 4000”内获得连接。
关于linux - 502 错误网关 HAproxy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18615126/