HAProxy http 检查 ssl?

HAProxy http check on for ssl?

我有一些 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打开网页(提示我This site can't provide a secure connection. ERR_SSL_PROTOCOL_ERROR)。

如果我删除那个参数,网页可以再次打开,但是所有的https服务器状态在HAProxy中都变成DOWN。

P.S。我目前使用的是自签名证书,因为我还在测试中。

我找到了解决方案:因为我在 apache 节点上使用 https,所以我必须将 ssl 证书内容复制到 haproxy。为此,将私钥和 CA 颁发的证书内容复制并合并到一个文件中(在我的例子中,我将其放入 /etc/haproxy/haproxy.pem)。

修改haproxy配置,更改

bind *:443

bind *:443 ssl crt /etc/haproxy/haproxy.pem