Can I healthcheck two endpoints for one service?

I have a scenario where I need to check that two different servers are up to consider service as up

If server A and server B is up - goto server B else goto server C

Is that doable?, if not - can I check server A as below;

If A is up go to server B
if A is down go server backup server C
(in this workaround scenario I will let server A check server B for me)

server B is in both scenarios the endpoint for the user, but ALSO depending on A status
server B is a blackbox so I can’t do anything there.

messy explaination - i hope somone understands it :slight_smile:

Hi Rickard
It is possible, but of course, if would be better to avoid such “hacky” requirements.
I don’t understand what you want to achieve.

Make sure you make a logical separation between servers (as in host running a webserver) and services (e.g. “”, “”) in your mind, and have a clear understanding before planning on which services should be running on which servers.

From your description, it is not clear which service should run on which server.
Is it the same service running on all three servers?

You may want to use Named ACL’s to define services (as in HTTP “host” header) and backends that are running a service.
You can then combine the acl names to build your own custom complex “routing” rule.

I made the following demo config, just to illustrate what haproxy could do (not tested):

frontend SERVICE-WEB
  bind *:443 name *:443 ssl crt MYCERT
  mode http
  acl   hdr(host) -i
  acl  hdr(host) -i
  acl isavail_Backend_A   nbsrv(Backend_A) gt 0
  acl isavail_Backend_B   nbsrv(Backend_B) gt 0
  acl isavail_Backend_C   nbsrv(Backend_C) gt 0
  use_backend Backend_B   if  isavail_Backend_A    isavail_Backend_B
  use_backend Backend_C   if  ! isavail_Backend_A  isavail_Backend_B   isavail_Backend_C

  use_backend Backend_A   if isavail_Backend_A

Keep in mind, Named ACL’s can also be used in backends.

However, it is always better use backends with multiple backend servers, and use check, backup and weight to determine which server will get the requests. Use cookie for session persistence if you need. This model is much more robust:

frontend SERVICE-WEB
  bind *:443 name *:443 ssl crt MYCERT
  mode http
  mode http
  cookie insert indirect nocache secure httponly attr SameSite=strict
  option httpchk HEAD / HTTP/1.1\r\nHost:\
  server server_A:443 ssl maxconn 500 weight 100 cookie srv1 check-ssl check
  server server_B:443 ssl maxconn 500 weight   1 cookie srv2 check-ssl check
  server server_C:443 ssl maxconn 500 weight 100 cookie srv3 check-ssl check backup

Hope this helps?

@Toni - this looks like an excellent idea, ACL’s I backend, never thought they would superceed the initial server list and their status, I will give it a test !