How can I configure HAProxy to treat primary and fallback backends as distinct servers when they point to the same machine?

I’m using HAProxy to load balance traffic to an application running on a single machine. I want to define a primary and a fallback backend, both pointing to the same server (same app, same machine), but I want HAProxy to treat them as logically distinct servers — so that if the primary fails (based on a health check), it will fail over to the fallback.

backend backend-1
    option httpchk GET /is_healthy
    http-check expect status 200

    server primary1   app-host.local-1:14240 check port 8080
    server primary2   app-host.local-2:14240 check port 8080

    server fallback1  app-host.local-1:14240 backup check disabled
    server fallback2  app-host.local-2:14240 backup check disabled

In this setup:

  • Port 8080 runs a lightweight health-check service (this logically just marks un-healthy)
  • Port 14240 is the actual application.
  • I intentionally return a non-200 on /is_healthy to simulate failure.
  • The fallback has health checks disabled, but should still receive traffic when both primary fails.

When the health check fails, HAProxy logs show no servers available, and I get a 503 Service Unavailable. It seems HAProxy doesn’t actually treat the fallback as a distinct server because the IP and port are the same.

You disabled fallback1 and fallback2 server by using the disabled keyword. You also enabled health checks on port 14240 by using the check keyword.

Remove the “check” as well as the “disabled” keyword from the fallback server configuration, the backup keyword is all you need, unless you have additional default configurations not shown in the above config expert that interfere as well.