ssl - HAProxy 在 TCP 模式下对 https 404 状态代码进行健康检查

标签 ssl https load-balancing wildfly haproxy

我有两台服务器,每台服务器都运行一台 Wildfly 应用程序服务器,并通过 https 提供一项服务。该服务正在处理 https 加密。在两台服务器前面,我有一个 HAProxy 作为 tcp 模式的负载均衡器,将 ssl 流量传递到这两个服务。

HAProxy 健康检查仅检查服务器是否在线,而不检查服务是否在线。如果服务未运行 Wildfly 返回:

<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. 选项 httpchk/server
    • httpchk 告诉 HAProxy 发送 http 请求并检查响应状态
    • /server 指定我的服务的 URI/子域
  2. 服务器后端1 wildfly:8443 检查 check-ssl 验证无
    • 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

关于ssl - HAProxy 在 TCP 模式下对 https 404 状态代码进行健康检查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38584795/

相关文章:

php - WampServer Apache 模块无法启动

ssl - 使用密码保护 SSL key 的 Apache 2 上的 logrotate 导致的失败

azure - 运行多个 Azure 云服务(Web 角色)实例是否需要负载均衡器?

IP 地址处的 Node.js HTTPS POST 请求失败

javascript - 点击 Node.js 站点时偶尔出现 ERR_CONNECTION_RESET 错误

java - 使用tomcat进行负载均衡

security - 我需要找到易受攻击的 openssl,以便我可以对其进行测试

java - 如何使用 java 使用属性或 VM 选项打开 SSL/TLS 验证?

java - 在 apache 上运行的 java web 应用程序的 HTTPS 问题

css - 在特定页面上通过 https 加载 css