HAProxy 健康检查在 https 404 状态码上的 tcp 模式

HAProxy health check in tcp mode on https 404 status code

我有两台服务器,每台 运行 一台 Wildfly 应用程序服务器,其中一项服务可通过 https 获得。该服务负责 https 加密。在两台服务器前面,我有一个 HAProxy 作为 tcp 模式的负载均衡器,用于将 ssl 流量传递给这两个服务。

HAProxy健康检查只检查服务器是否在线,不检查服务。如果服务不是运行 Wildfly returns:

<html><head><title>Error</title></head><body>404 - Not Found</body></html>

HAProxy 将其解释为健康。

HAProxy 配置:

global  
    maxconn 2000

defaults
    log     global
    mode    http
    option  dontlognull
    retries 3
    option redispatch
    timeout connect  5000
    timeout client  10000
    timeout server  10000

listen backend
    bind *:8443
    mode tcp
    balance roundrobin
    option httpclose
    server backend1 wildfly:8443 check
    server backend2 xxx.xxx.xxx.xxx:8443 check

如何让 HAProxy 了解 404 - Not Found 健康。

两行就可以了:

  1. option httpchk /server
    • httpchk 告诉 HAProxy 发送一个 http 请求并检查响应状态
    • /server 指定我的服务的 URI / 子域
  2. server backend1 wildfly:8443 check check-ssl verify none
    • check-ssl 告诉 HAProxy 通过 https 而不是 http
    • 检查
    • verify none 告诉 HAProxy 信任服务的 ssl 证书(或者您可以指定一个 .pem 文件)

完整的 HAProxy 配置:

global  
    maxconn 2000

defaults
    log     global
    mode    http
    option  dontlognull
    retries 3
    option redispatch
    timeout connect  5000
    timeout client  10000
    timeout server  10000

listen backend
    bind *:8443
    mode tcp
    balance roundrobin
    option httpchk /server
    server backend1 xxx.xxx.xxx.xxx:8443 check check-ssl verify none
    server backend2 xxx.xxx.xxx.xxx:8443 check check-ssl verify none