haproxy httpchk multiple check on backend

Probably, it'd be easier to make a "wrapper" PHP: it checks the other files, and if everything is ok, it returns with HTTP code 200, if not, 404.

As I remember, this worked for us too when we wanted functionality check too.


Ah, I had the same question! Our developers produced a multi-function Web service off one URL name, because we need to support non-CORS-compliant browsers (IE 8 and 9). One DNS name leading to one VIP address has several subdirectories, each a different application. So our load balancer has to health-check each one of the services, and then treat it as a big "AND" test, i.e., if even one of the services doesn't pass the check, then we must yank that server out of the farm until all of them pass.

We're transitioning over from Cisco ACE load balancers, and on that platform, you simply define multiple "probe" configs and then call for multiple probes within a single server farm, one line after another, and it runs all the probes. As you probably discovered, HAProxy doesn't let you define more than one "option httpchk"... or at least it ignores all but one of them, so you don't get the testing you're after. But I figured out from the manual that I could do it by not using httpchk, substituting a series of "connect, send, check" lines under "option tcp-check". It works perfectly.

option tcp-check
tcp-check connect
tcp-check send GET\ /FirstApplication/check.aspx?healthcheck\ HTTP/1.0\r\n\r\n
tcp-check expect string Healthy
tcp-check connect
tcp-check send GET\ /SecondApplication/check.aspx\ HTTP/1.0\r\n\r\n
tcp-check expect string YesThisIsGood
tcp-check connect
tcp-check send GET\ /ThirdApp/Check.aspx\ HTTP/1.0\r\n\r\n
tcp-check expect string ExpectedCheckResult
tcp-check connect
tcp-check send GET\ /NumberFourApp/check.aspx\ HTTP/1.0\r\n\r\n
tcp-check expect string YesItIsWorking

Note that you have to backslash-escape each space in the string you're sending. I'm using HTTP/1.0 in the request, which by default doesn't do keepalive, so I'm reconnecting in each series of lines. I suppose I could also use HTTP/1.1, but then I'd also have to transmit a Host header, so I think it's easier this way. Running these four checks in a row, it still takes only 60ms, so I'm satisfied. Also note that I'm just using "expect string", but there's also an "expect rstring" for regular expression searching through the result content coming back from the server.