This assumes you have installed HAProxy and have configured HAProxy to load balance a single websites across two or more web servers.
Let's say the servers www1.example.com and www2.example.com are producing the www.example.com and stage.example.com domains.
check can be used to configure HAProxy to check the health of backends.
HAProxy will try to establish a TCP connection every two seconds.
After three failed connections, the server is removed temporarily, until HAProxy gets at least two successful connections, after which it reinstates the server into the backend.
You can customize these settings, changing the interval, the number of failed checks that trigger a removal, or the number of successful checks that reinstate the server.
Here is an example of using check on two different backends.
frontend main
bind *:80
bind *:443 ssl crt /etc/pki/tls/foo.pem
balance roundrobin
acl www hdr(host) -i www.example.com
use_backend www_example_com if www
acl stage hdr(host) -i stage.example.com
use_backend stage_example_com if stage
default_backend www_example_com
backend www_example_com
server www1 www1.example.com:80 check
server www2 www2.example.com:80 check
backend stage_example_com
server stage1 www1.example.com:18080 check
server stage2 www2.example.com:18080 check
And here is example including inter 10s (interval, check once every 10 seconds) and fall 5 (the health check must fail 5 times for the backend to be temporarily removed) and rise 5 (return the backend after 5 successful health checks).
backend www_example_com
server www1 www1.example.com:80 check inter 10s fall 5 rise 5
server www2 www2.example.com:80 check inter 10s fall 5 rise 5
backend stage_example_com
server stage1 www1.example.com:18080 check inter 10s fall 5 rise 5
server stage2 www2.example.com:18080 check inter 10s fall 5 rise 5
Did you find this article helpful?
If so, consider buying me a coffee over at