我将Apache作为反向代理运行,重定向到HaProxy服务器设置,使用cookie在两个后端服务器之间进行负载 balancer . 它不优雅,但一切正常......

后端服务器运行一个使用基本身份验证的Web应用程序(它提供了所有功能),如果用户输入错误的登录详细信息,则后端应用程序会超时 . 结果HaProxy显示504错误 .

为了帮助我的用户正确登录,我已经为504错误以及503和502组合了自定义错误页面,这些页面会在某些时候显示 . 其他时候,浏览器中会显示一个标准错误页面,该页面与我定义的错误页面无关,并且与HaProxy附带的默认页面完全不同(例如/etc/haproxy/errors/504.http等) .

错误页面在全局部分以及每个后端部分中定义 . 它们很小~1800字节,是有效的HTML

看起来浏览器会读取HTTP响应,有些时候会显示自己的页面版本 . 然后,他们还会缓存错误页面,以便当用户再次尝试访问该页面时,将再次提供错误页面,而不是拉动页面并显示基本身份验证登录框 . 让登录框重新出现的唯一方法是关闭浏览器,重新打开它,然后导航回登录URL .

我忘了坐在我的HaProxy服务器前面的Apache反向代理,并想知道我的后端服务器是否发送了503错误,然后被HaProxy grab 了,而这又被Apache grab 了 . 为了测试这个,我更改了我的自定义HaProxy错误页面,以便它们向Apache返回200 OK状态 . 它工作一次,但后来默认回到标准消息:

Proxy Error

The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request

Reason: Error reading from remote server

每个错误文件看起来像这样:

HTTP/1.0 504 Gateway Time-out
Cache-Control: no-cache
Connection: close
Content-Type: text/html

<html>
<head>
<title>Username and/or password error</title>
</head>
<body>
<p>Some explanatory text ...</p>
</body>
</html>

这里发生了什么 ?如何使我的自定义错误页面始终显示?那么不要在用户浏览器中缓存?

我已经多次重新加载并重新启动了编辑haproxy.cfg的haproxy . 这是我的haproxy.cfg文件:

global
    log /dev/log    local0
    log /dev/log    local1 notice
    chroot /var/lib/haproxy
    stats socket /run/haproxy/admin.sock mode 660 level admin
    stats timeout 30s
    user haproxy
    group haproxy
    daemon

    # Default SSL material locations
    ca-base /etc/ssl/certs
    crt-base /etc/ssl/private

    # Default ciphers to use on SSL-enabled listening sockets.
    # For more information, see ciphers(1SSL). This list is from:
    #  https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/
    ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS
    ssl-default-bind-options no-sslv3

defaults
    log     global
    mode    http
    option  httplog
    option  dontlognull
    timeout connect 5000
    timeout client  30000
    timeout server  30000
    errorfile 400 /etc/haproxy/errors/400.http
    errorfile 403 /etc/haproxy/errors/403.http
    errorfile 408 /etc/haproxy/errors/408.http
    errorfile 500 /etc/haproxy/errors/500.http
    errorfile 502 /etc/haproxy/errors/502-custom.http
    errorfile 503 /etc/haproxy/errors/503-custom.http
    errorfile 504 /etc/haproxy/errors/504-custom.http

frontend http_front
   bind *:8085
   stats uri /haproxy?stats

   acl is_S0 hdr_sub(cookie) S0
   acl is_S1 hdr_sub(cookie) S1

   use_backend backend_S0 if is_S0
   use_backend backend_S1 if is_S1
   default_backend backend_S0

backend backend_S0
   server Public0 xxx.xxx.xxx.xxx:8080 check
   errorfile 502 /etc/haproxy/errors/502-custom.http
   errorfile 503 /etc/haproxy/errors/503-custom.http
   errorfile 504 /etc/haproxy/errors/504-custom.http


backend backend_S1
   server Public1 yyy.yyy.yyy.yyy:8080 check
   errorfile 502 /etc/haproxy/errors/502-custom.http
   errorfile 503 /etc/haproxy/errors/503-custom.http
   errorfile 504 /etc/haproxy/errors/504-custom.http