linux - 502 错误网关 HAproxy

标签 linux tomcat ubuntu proxy haproxy

我运行的是 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/

相关文章:

python - 使用 Python 测试 vi 编辑器功能?

linux - 查询 : Why am I getting a clang error on my OSX terminal?

java - 某些服务器上的 MySQL 数据截断错误

python-3.x - 升级 Python 版本以运行和创建 Sagemaker Endpoint 的自定义容器

c++ - 获取 Eclipse(版本 3.8)以将 C++11 用于 Ubuntu 15.10

linux - Perl 和 Linux? : Make a log reader script run daily and weekly (automatic)

linux - 如何在cshrc中设置本地bin文件的路径

debugging - 当服务器有多个虚拟主机运行时如何远程调试 Tomcat (JPDA)

jsp - 在 Tomcat 6 中禁用浏览器缓存

django - 关于 wsgi.py 中 wsgi 模块的 Ubuntu 16.04 服务器错误