【发布时间】:2026-01-20 22:35:01
【问题描述】:
我有一些 Web 服务器,它们是 MySQL 后端。 HAProxy 位于这些 Web 服务器的前面。所有网络服务器都使用 https。
我尝试在 http 和 https 上使用 http 检查选项来确保如果数据库连接丢失,HAProxy 将故障转移到另一个节点。我的 haproxy 配置文件:
global
log /dev/log local0
maxconn 4096
#debug
#quiet
user haproxy
group haproxy
defaults
log global
mode http
option httplog
option dontlognull
retries 3
option redispatch
maxconn 2000
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
listen http
bind *:80
mode http
balance roundrobin
stats enable
stats auth haproxy:haproxy
cookie JSESSIONID prefix
stick on src table https
option http-server-close
option forwardfor
default-server inter 5s fall 2
option httpchk
http-check expect ! string Database\ error
server sitea 192.168.0.20 cookie sitea check port 80
server siteb 192.168.0.21 cookie siteb check port 80
listen https
bind *:443
mode tcp
balance roundrobin
stick-table type ip size 5000k expire 2h store conn_cur
stick on src
option tcplog
option ssl-hello-chk
default-server inter 5s fall 2
option httpchk
http-check expect ! string Database\ error
server sitea 192.168.0.20:443 check ssl verify none
server siteb 192.168.0.21:443 check ssl verify none
看看最后两行。如果我指定“ssl verify none”,我的 HAProxy 可以成功检查 Apache 和 MySQL 状态。但是,我无法通过 https 打开网页(它提示我此站点无法提供安全连接。ERR_SSL_PROTOCOL_ERROR)。
如果我删除该参数,网页可以再次打开,但所有 https 服务器状态在 HAProxy 中变为 DOWN。
附:我目前正在使用自签名证书,因为我还在测试中。
【问题讨论】:
-
直接测试你的后端。问题似乎出在他们身上,因为 HAProxy 位于
mode tcp。 -
后端完美运行。我认为这是因为 haproxy 无法重定向 ssl 连接。