I'm setting up an HAProxy in front of only 2 backend servers, with a particular configuration: any request should go to server A; but, if server A returns a 5xx error code, all request should go to a backup server B. When A returns "up", all the requests should go to A.

I'm trying this configuration:

backend example_cluster
        balance roundrobin
        option httpclose
        option forwardfor

        option httpchk HEAD /ping.html HTTP/1.0\r\nHost:www.example.com
        http-check disable-on-404
        default-server error-limit 1 on-error mark-down

        redirect scheme https if !{ ssl_fc }
        server node1 check observe layer7
        server node_back backup ssl verify none

But it doesn't work for two reasons:

  1. All requests are routed to server node_back (B), even if node1 (A) is up.
  2. It seems that no httpchecks are performed against server A; or better, in syslog I don't see any error regarding the server A down.

If I remove the "option httpchk" line, and the two lines just below that; and I remove also the "observe layer7" in server A; HAProxy works by routing all requests to node A. But, obviously, when the server A returns a 500, HAProxy does not switch to B. So, I'm assuming that the problem might be in the option httpchk configuration.

  • 1
    It's perfectly doable with nginx. In fact, I'm avoiding haproxy on web-balancing, because nginx is more flexible and simple, since it's a web-server. But, since the initial question was about haproxy, I don't feel the right to provide an answer about nginx. But if you want it, I can. After all, almost a year has passed, I think you have found a solution anyway. – drookie Jan 25 '16 at 6:59

From the official documentation: Active Passive Load Balancing With HAProxy

  mode http
  option http-server-close
  timeout client 20s
  timeout server 20s
  timeout connect 4s

frontend ft_app
  bind name app
  default_backend bk_app

backend bk_app
  server s1 check
  server s2 check backup
| improve this answer | |

By the way I've found pre-nginx configuration for my haproxy, and I think you should give it a try:

frontend foo
    option httpchk
    default_backend bar-web

backend bar-web
    mode http
    balance roundrobin
    server bar1 check observe layer4 weight 50
    server bar2 check observe layer4 weight 50
| 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.