# Active/Passive Configuration for Multiple Backends

**URL:** <https://discourse.haproxy.org/t/active-passive-configuration-for-multiple-backends/4124>\
**Category:** Help!\
**Created:** [August 1, 2019, 6:12am UTC](https://discourse.haproxy.org/t/active-passive-configuration-for-multiple-backends/4124 "2019-08-01T06:12:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![void\_in](https://avatars.discourse-cdn.com/v4/letter/v/3ec8ea/32.png) [@void\_in](https://discourse.haproxy.org/u/void_in)\
**Post date:** [August 1, 2019, 6:12am UTC](https://discourse.haproxy.org/t/active-passive-configuration-for-multiple-backends/4124/1 "2019-08-01T06:12:19Z")

</div>

First of all congratulations for having a great open source community. So by using the backup keyword, we can configure the HAProxy to shift to the backup server (or servers) in case all the primary servers are down. But I couldn’t find a config example where I have 2 backends with 2 backups:

server1 1.1.1.1:8080 check  
server1 2.2.2.2:8080 check backup  
server1 3.3.3.3:8080 check  
server1 4.4.4.4:8080 check backup

I want to shift to 2.2.2.2 in case 1.1.1.1 is down. Also I want to shift to 4.4.4.4 in case 3.3.3.3 is down. Configuration manual says (and in my testing) the HAProxy only shifts to the backup servers once both 1.1.1.1 and 3.3.3.3 are down. Is there anyway I can configure the backup servers separately for each server? I my description is clear.

Thank you very much.

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [August 1, 2019, 9:13am UTC](https://discourse.haproxy.org/t/active-passive-configuration-for-multiple-backends/4124/2 "2019-08-01T09:13:46Z")

</div>

No, it isn’t possible (and I don’t see how it makes sense).

Please explain the entire use-case and configuration so that we can understand what you are trying to achieve and make a suggestion.

---

<div class="post-metadata">

**Author:** ![void\_in](https://avatars.discourse-cdn.com/v4/letter/v/3ec8ea/32.png) [@void\_in](https://discourse.haproxy.org/u/void_in)\
**Post date:** [August 1, 2019, 9:44am UTC](https://discourse.haproxy.org/t/active-passive-configuration-for-multiple-backends/4124/3 "2019-08-01T09:44:49Z")

</div>

Thank you for the response and let me clarify.

So HAProxy only shifts to the backup servers once all the primary servers are down. In our setup, we have two backend primary servers serving API stateless requests. However, during the course of operation, one or both servers become unavailable due to a driver crash. What we want is that we setup HAProxy in such a way that if one of the primary servers are down, the backup server takes over in its place.

This is the configuration:  
frontend api\_frontend\_8080  
bind 0.0.0.0:8080  
default\_backend api\_backend\_8080

> backend api\_backend\_8080  
> balance roundrobin  
> option forwardfor  
> server S1 10.1.1.1:8080 check port 8080 inter 5s  
> server S2 10.1.1.2:8080 check port 8080 inter 5s backup  
> server S3 10.1.1.3:8080 check port 8080 inter 5s  
> server S4 10.1.1.4:8080 check port 8080 inter 5s backup

S2 is the backup of S1 so if S1 is unavailable, S2 should serve the API requests. It should not be dependent on the availability of S3. Right now, S2 will only server contents once both S1 and S3 is down.

Thanks once again Lukas for your time and help.

---

<div class="post-metadata">

**Author:** ![davedeveloper](https://avatars.discourse-cdn.com/v4/letter/d/a8b319/32.png) [@davedeveloper](https://discourse.haproxy.org/u/davedeveloper)\
**Post date:** [July 20, 2021, 5:08pm UTC](https://discourse.haproxy.org/t/active-passive-configuration-for-multiple-backends/4124/4 "2021-07-20T17:08:35Z")

</div>

I would suggest Chaining

create 2 backends

> backend api\_backend\_8081  
> balance roundrobin  
> option forwardfor  
> server S1 10.1.1.1:8080 check port 8080 inter 5s  
> server S2 10.1.1.2:8080 check port 8080 inter 5s backup

> backend api\_backend\_8082  
> balance roundrobin  
> option forwardfor  
> server S3 10.1.1.3:8080 check port 8080 inter 5s  
> server S4 10.1.1.4:8080 check port 8080 inter 5s backup

then create a backend to talk those backends

> backend api\_backend\_8080  
> balance roundrobin  
> option forwardfor  
> server S3 127.0.0.1:8081 check port 8081 inter 5s  
> server S4 127.0.0.1:8082 check port 8082 inter 5s
