最近在学习 HAProxy,这家伙的负载均衡功能比 Nginx 的强大,其支持 HTTP2 协议回源是我决定切换到 HAProxy 的一个原因。过程中遇到 haproxy[102388]: backend backend_default_ssl has no server available 的错误,实际上后端服务器运行的状态是正常的,所以推断是配置的参数出了问题,在 Google 的帮助下,我在 https://stackoverflow.com/questions/69633436/haproxy-no-server-is-available-to-handle-this-request 找到了解决方法,在此记录一下。
这是原配置:
backend backend_default_ssl
filter compression
compression algo gzip
compression type text/css text/html text/javascript application/javascript text/plain text/xml application/json image/svg+xml application/xml
mode http
balance roundrobin
http-request set-header Host www.kzwr.com
server my_server_1 10.0.24.16:443 ssl alpn h2 sni str(www.kzwr.com) ssl verify none check
server my_server_2 10.0.24.17:443 ssl alpn h2 sni str(www.kzwr.com) ssl verify none check
这是解决问题后的配置:
backend backend_default_ssl
filter compression
compression algo gzip
compression type text/css text/html text/javascript application/javascript text/plain text/xml application/json image/svg+xml application/xml
mode http
balance roundrobin
http-request set-header Host www.kzwr.com
server my_server_1 10.0.24.16:443 ssl alpn h2 sni str(www.kzwr.com) ssl verify none check port 443
server my_server_2 10.0.24.17:443 ssl alpn h2 sni str(www.kzwr.com) ssl verify none check port 443
区别的地方在 check 参数,第一份配置没有为 check 参数配置 port ,第二份配置为 check 参数指定了 443 端口,修改后执行 haproxy -c -f /etc/haproxy/haproxy.cfg 检查配置是否正常,重启 HAProxy 后问题顺利解决。