Zero-Downtime with HAProxy
Putting up a maintenance page while you are doing an update and restarting your application servers is good practice, but it definitely hurts the user experience. setup a html page and check url – e.g. /haproxy_check.html. It will check the haproxy_check.html every 2 seconds and check the string OK inside the the htmp page if found which mean web server and if not it means web server is not responding so it mark it down and start sending the traffic of that node to another active node. Once the down server up it will start sending the new traffic to this node.
Another way of doing the same thing: Zero-Downtime Restarts with HAProxy
Example of Backends
option httpchk GET /haproxy_check.html
http-check expect rstring OK
server WEB1 127.0.0.1:80 maxconn 2 check inter 2000
server WEB2 127.0.0.1:8080 maxconn 2 check inter 2000
Balance with hdr
We use this option because we want to send all same type of request to one server or backend and will do the load balancing only when the that server or backend is not responding.
About balance hdr algorithm
The HTTP header <name> will be looked up in each HTTP request.Just as with the equivalent ACL ‘hdr()’ function, the header name in parenthesis is not case sensitive. If the header is absent or if it does not contain any value, the roundrobin algorithm is applied instead.
An optional ‘use_domain_only’ parameter is available, for reducing the hash algorithm to the main domain part with some specific headers such as ‘Host’. For instance, in the Host value “haproxy.manoj.com”, only “WEB1″ will be considered.
This algorithm is static by default, which means that changing a server’s weight on the fly will have no effect, but this can be changed using “hash-type”.