I have a load balancer running HAProxy with two backend servers both running Nginx on to Unicorn.

If nginx goes down on one of these boxes HAProxy takes it out of the set and the service continues to operate.

If unicorn goes down nginx starts serving up 502 errors and HAProxy happily forwards them on to the client.

As I see it there are two possible solutions:

  • Configure nginx not respond at all if it can't connect to unicorn. HAProxy will think its down and no longer send requests there.
  • Configure haproxy to consider 502s as server down and not send any more requests to there.

Neither of which I can work out how to do


From Unicorn, you shall have a "ping" page that responds with "OK" if the application is up and running fine. Then use that page as a healthcheck in haproxy by using http-check-expect.

| improve this answer | |
  • See my answer below for the actual code I ended up using – msaspence Apr 17 '14 at 17:39

Credit to @florin-asavoaie for pointing me in the write direction on this one. Here's a full write up:

I already had a json page at /status that returned {"status":"up"}

So I added

option httpchk GET /status
http-check expect string up

To my backend in haproxy.cfg and restarted haproxy

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.