HAProxy – HTTP Server error detection

haproxyhttp

I want to use HAProxy for load balancing and failover of an Apache-PHP application hosted on many identical backend servers. Is there any way of detecting a failed node on HAproxy and removing it from the active group of nodes with in the context of a single HTTP request with out returning a 5xx error.

Ideally the server can return a Response Header – "Status: Error" and HAProxy should detect this header and remove that particular node from the active set.

I cannot return 5xx error from my app.

Is such a configuration possible for HAProxy?

Best Answer

A 5xx response is still a response, so by default it would be passed onto the client.

I haven't seen a product that goes to the level you mention out of the box. If none do exist, you need a load balancer that allows you to write a custom post response rule, and for that rule to have access to modify the state of the bad node in the pool and feed the request back into your pool. F5 BigIP's, Riverbed StingRay (Zues) certainly offer the scripting element and node management (f5 e.g. down the bottom). Varnish and Squid although not pure load balancers do offer the ability to modify responses post backend response as well. I'm not sure about their access to the node/pool management though. Note that you would also need to deal with request timeouts in the same manner as 5xx responses.

The page you use to monitor a nodes status would also need be something that thoroughly test's the applications status and can be hit quite frequently

The closest HAProxy looks to come to this is observe <mode> which allows it to react to errors that occur in regular traffic.

I cannot return 5xx error from my app.

At some point it's going to happen, cater for it.