Linux – HAProxy loadbalanced backend – behaviour when one server down

haproxylinuxload balancing

My understanding was that with two server backends load-balanced by HAProxy , if one goes down, HAProxy should be able to direct all traffic to the other.

I have two loadbalaced webservers, with roundrobin and httpchk, but when one goes down I get 503 - Service unavailable messages from HAProxy. Perhaps there is something wrong with my config?

backend app
    timeout server 50000ms
    mode http
    balance roundrobin
    option httpchk

    server ap1 ap1:8000 maxconn 4000 #ap1 is hostname
    server ap2 ap2:8000 maxconn 4000 #ap2 is hostname

Best Answer

Maybe it helps if you add an explicit URL to your httpchk - per default it uses an http OPTION on /. Also you have to add the "check" keyword to your host definitions (http://haproxy.1wt.eu/download/1.3/doc/haproxy-en.txt section 3.1)

backend app
    timeout server 50000ms
    mode http
    balance roundrobin
    option httpchk HEAD /some/valid/url

    server ap1 ap1:8000 maxconn 4000 check #ap1 is hostname
    server ap2 ap2:8000 maxconn 4000 check #ap2 is hostname