Let's say I have web01 in my list of backend servers, and web01 goes down. It will take a few seconds for HAProxy to notice the server is down (depending on the health check interval and how long the timeout is) and take it out of rotation. If a request comes in before that's happened, the client will end up receiving a 503 Service Unavailable error.

What I'd like to happen is to have HAProxy automatically re-try that same request again on another server. I realize the request would end up being really slow, but it would end up resulting in a success rather than an error.

Is there a way to configure HAProxy to retry the HTTP request on another server instead of erroring out? Ideally, I don't ever want a client to receive an error if there's any working servers in the cluster.

Here's my haproxy.cfg:

        maxconn 4096

        mode    http
        contimeout      5000
        clitimeout      50000
        srvtimeout      50000

frontend http-in
        bind *:80
        acl service1 path_reg ^/service1/
        acl service2 path_reg ^/service2/
        use_backend service1 if service1
        use_backend service2 if service2

backend service1
        server web01 check
        server web02 check
        reqrep ^([^\ :]*)\ /service1/(.*)     \1\ /\2

backend service2
        server web03 check
        server web04 check
        reqrep ^([^\ :]*)\ /service2/(.*)     \1\ /\2

You want option redispatch. This causes a request that fails to be retried on another server.

| improve this answer | |
  • Thanks! I did look at that option in the docs, but it appeared to be something about breaking sticky session rules if the server was down so I figured it wasn't relevant. But I just tried it and it indeed does exactly what I need. – Mike Christensen Apr 11 '14 at 18:32
  • Just wanted to add that in cases that even the other servers in the cluster are down and you don't want your visitors to get an HTTP 503 error, you could also add a backup server by adding a server with 'backup' (server bck01 check backup). – Robbietjuh Apr 11 '14 at 19:19

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.