8

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 1.2.3.4:80 check observe layer7
        server node_back 5.6.7.8:443 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 06:59

2 Answers2

1

From the official documentation: Active Passive Load Balancing With HAProxy

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

frontend ft_app
  bind 10.0.0.100:80 name app
  default_backend bk_app

backend bk_app
  server s1 10.0.0.1:80 check
  server s2 10.0.0.2:80 check backup
user5994461
  • 2,919
  • 1
  • 18
  • 31
0

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

frontend foo
    bind 192.168.0.1:9080
    option httpchk
    default_backend bar-web

backend bar-web
    mode http
    balance roundrobin
    server bar1 192.168.1.2:9080 check observe layer4 weight 50
    server bar2 192.168.1.3:9080 check observe layer4 weight 50
drookie
  • 8,625
  • 1
  • 19
  • 29