# Last resort backend

**URL:** <https://discourse.haproxy.org/t/last-resort-backend/3387>\
**Category:** Help!\
**Created:** [January 11, 2019, 8:58am UTC](https://discourse.haproxy.org/t/last-resort-backend/3387 "2019-01-11T08:58:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![simonuk1](https://avatars.discourse-cdn.com/v4/letter/s/85e7bf/32.png) [@simonuk1](https://discourse.haproxy.org/u/simonuk1)\
**Post date:** [January 11, 2019, 8:58am UTC](https://discourse.haproxy.org/t/last-resort-backend/3387/1 "2019-01-11T08:58:34Z")

</div>

Is it possible to define a backend that can be used by all other backend as its last resort.

Ie normal backends will have 2 servers defined, if both those servers are down or then uses the last resort backend.

I know there is the backup flag that can be set per server in the backend config, but that does mean defining it in every backend.

Cheers  
Simon

---

<div class="post-metadata">

**Author:** ![ciprian.craciun](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.haproxy.org/ciprian.craciun/32/722_2.png) [@ciprian.craciun](https://discourse.haproxy.org/u/ciprian.craciun)\
**Post date:** [January 11, 2019, 5:52pm UTC](https://discourse.haproxy.org/t/last-resort-backend/3387/2 "2019-01-11T17:52:54Z")

</div>

You could use the following “trick”:

- in your frontend I assume you have some ACL’s that are used to route the requests to various backends as such `use_backend service_1 if route_1`;
- now there is a sample `nbsrv` ( [http://cbonte.github.io/haproxy-dconv/1.8/configuration.html#7.3.2-nbsrv](http://cbonte.github.io/haproxy-dconv/1.8/configuration.html#7.3.2-nbsrv) ) that returns the number of live servers;
- you could create a special ACL for the case when no servers are available as `acl service_1_down nbsrv(service_1) eq 0`;
- then you could insert a new routing rule in the frontent that uses the newly introduced ACL; (however you need to define one backend which contains the fallback server;)
- (BTW, I always include a `default_fallback` rule in my frontends, and I always have such a `fallback` backend even if I have so live servers declared so I can handle such situations more easily;)

Thus tu summarize:

```auto
frontend main
    acl route_1 ...
    acl service_1_down nbsrv(service_1) eq 0
    use_backend fallback if route_1 service_1_down
    use_backend service_1 if route_1
    default_backend fallback

backend service_1
   ...

backend fallback
   ...

```
