HAProxy, health checking multiple servers with different host names
Posted
by
Marco Bettiolo
on Server Fault
See other posts from Server Fault
or by Marco Bettiolo
Published on 2014-05-13T01:38:13Z
Indexed on
2014/05/28
21:34 UTC
Read the original article
Hit count: 226
haproxy
I need to load balance between multiple running servers with different host names. I cannot set-up the same virtual host on each one.
Is it possible to have only one listen configuration with multiple server and make the Health Checks apply the http-send-name-header Host
directive? I am using HAProxy 1.5.
I came up with this working haproxy.cfg, as you can see, I had to set a different hostname for each health check as the health check ignores the http-send-name-header Host
. I would have preferred to use variables or other methods and keep things more concise.
global
log 127.0.0.1 local0 notice
maxconn 2000
user haproxy
group haproxy
defaults
log global
mode http
option httplog
option dontlognull
retries 3
option redispatch
timeout connect 5000
timeout client 10000
timeout server 10000
stats enable
stats uri /haproxy?stats
stats refresh 5s
balance roundrobin
option httpclose
listen inbound :80
option httpchk HEAD / HTTP/1.1\r\n
server instance1 127.0.0.101 check inter 3000 fall 1 rise 1
server instance2 127.0.0.102 check inter 3000 fall 1 rise 1
listen instance1 127.0.0.101:80
option forwardfor
http-send-name-header Host
option httpchk HEAD / HTTP/1.1\r\nHost:\ www.example.com
server www.example.com www.example.com:80 check inter 5000 fall 3 rise 2
listen instance2 127.0.0.102:80
option forwardfor
http-send-name-header Host
option httpchk HEAD / HTTP/1.1\r\nHost:\ www.bing.com
server www.bing.com www.bing.com:80 check inter 5000 fall 3 rise 2
© Server Fault or respective owner