我有两台服务器,每台服务器都运行一台 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
是不健康的。
最佳答案
两行就可以了:
选项 httpchk/server
httpchk
告诉 HAProxy 发送 http 请求并检查响应状态/server
指定我的服务的 URI/子域
服务器后端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/