# Can I healthcheck two endpoints for one service?

**URL:** <https://discourse.haproxy.org/t/can-i-healthcheck-two-endpoints-for-one-service/7556>\
**Category:** Help!\
**Created:** [April 7, 2022, 12:16pm UTC](https://discourse.haproxy.org/t/can-i-healthcheck-two-endpoints-for-one-service/7556 "2022-04-07T12:16:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rickard\_505](https://avatars.discourse-cdn.com/v4/letter/r/5f9b8f/32.png) [@Rickard\_505](https://discourse.haproxy.org/u/Rickard_505)\
**Post date:** [April 7, 2022, 12:16pm UTC](https://discourse.haproxy.org/t/can-i-healthcheck-two-endpoints-for-one-service/7556/1 "2022-04-07T12:16:48Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![Toni](https://avatars.discourse-cdn.com/v4/letter/t/8797f3/32.png) [@Toni](https://discourse.haproxy.org/u/Toni)\
**Post date:** [April 13, 2022, 3:15pm UTC](https://discourse.haproxy.org/t/can-i-healthcheck-two-endpoints-for-one-service/7556/2 "2022-04-13T15:15:38Z")

</div>

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. “[mail.acme.org](http://mail.acme.org)”, “[www.acme.org](http://www.acme.org)”) 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):

```auto
frontend SERVICE-WEB
  bind *:443 name *:443 ssl crt MYCERT
  mode http
  acl ishost_www.acme.org hdr(host) -i www.acme.org
  acl ishost_mail.acme.org hdr(host) -i mail.acme.org
  
  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 ishost_www.acme.org isavail_Backend_A isavail_Backend_B
  use_backend Backend_C if ishost_www.acme.org ! isavail_Backend_A isavail_Backend_B isavail_Backend_C

  use_backend Backend_A if ishost_mail.acme.org 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:

```auto
frontend SERVICE-WEB
  bind *:443 name *:443 ssl crt MYCERT
  mode http
  default Backend_www.acme.org
  
backend Backend_www.acme.org
  mode http
  cookie LB-www.acme.org insert indirect nocache secure httponly attr SameSite=strict
  option httpchk HEAD / HTTP/1.1\r\nHost:\ www.acme.org
  server server_A:443 1.2.10.11:443 ssl maxconn 500 weight 100 cookie srv1 check-ssl check
  server server_B:443 1.2.10.12:443 ssl maxconn 500 weight 1 cookie srv2 check-ssl check
  server server_C:443 1.2.10.13:443 ssl maxconn 500 weight 100 cookie srv3 check-ssl check backup

```

Hope this helps?  
Toni

---

<div class="post-metadata">

**Author:** ![Rickard\_505](https://avatars.discourse-cdn.com/v4/letter/r/5f9b8f/32.png) [@Rickard\_505](https://discourse.haproxy.org/u/Rickard_505)\
**Post date:** [April 14, 2022, 8:15am UTC](https://discourse.haproxy.org/t/can-i-healthcheck-two-endpoints-for-one-service/7556/3 "2022-04-14T08:15:11Z")

</div>

@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 !

---

<div class="post-metadata">

**Author:** ![Rickard\_505](https://avatars.discourse-cdn.com/v4/letter/r/5f9b8f/32.png) [@Rickard\_505](https://discourse.haproxy.org/u/Rickard_505)\
**Post date:** [December 13, 2023, 12:41pm UTC](https://discourse.haproxy.org/t/can-i-healthcheck-two-endpoints-for-one-service/7556/4 "2023-12-13T12:41:00Z")

</div>

Just confirming this worked fine !
