# Routing urls to different backends in haproxy

**URL:** <https://linux-tips.com/t/routing-urls-to-different-backends-in-haproxy/24>\
**Category:** Services\
**Created:** [December 14, 2014, 6:36pm UTC](https://linux-tips.com/t/routing-urls-to-different-backends-in-haproxy/24 "2014-12-14T18:36:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![demirten](https://linux-tips.com/user_avatar/linux-tips.com/demirten/32/64_2.png) [@demirten](https://linux-tips.com/u/demirten)\
**Post date:** [December 14, 2014, 6:36pm UTC](https://linux-tips.com/t/routing-urls-to-different-backends-in-haproxy/24/1 "2014-12-14T18:36:15Z")

</div>

Haproxy is a very advanced layer7 opensource loadbalancer software. If you want to decrease priority of some urls in your setup, you can define ACL rules to detect traffic type and route to different backends which can have different servers or maximum connection parameter like below:

```
frontend http
    bind *:80
    mode http
    acl url_slow path_beg /import/log
    acl url_slow path_beg /job/execute
    use_backend slow-backend if url_slow
    default_backend rails-backend
    
backend rails-backend
    option http-server-close
    balance roundrobin
    option httpchk GET /check HTTP/1.0
    server app1 10.0.0.1:80 check inter 5000 rise 2 fall 2 weight 50 maxconn 100
    server app2 10.0.0.2:80 check inter 5000 rise 2 fall 2 weight 50 maxconn 100
    
backend slow-backend
    option http-server-close
    balance roundrobin
    option httpchk GET /check HTTP/1.0
    server app1 10.0.0.1:80 check inter 5000 rise 2 fall 2 weight 5 maxconn 1
    server app2 10.0.0.2:80 check inter 5000 rise 2 fall 2 weight 5 maxconn 1
    server app3 10.0.0.3:80 check inter 5000 rise 2 fall 2 weight 90 maxconn 100

```

In this example, we define an acl named `url_slow` to select specific urls which begins with specific words. Haproxy has different selectors, we used `path_begin` here. You can define multiple acl like this.

After acl setup, you can select different backends for specific acl. We used `slow-backend` here for acl `url_slow`. With this setup, our application servers `app1` and `app2` used in both backends but limited with different `maxconn` parameters **1** and **100**. With this setup when you have high traffic on the paths which takes much time to complete, it won’t be fill your main application servers `app1` and `app2`

---

<div class="post-metadata">

**Author:** ![Shailesh\_Paudyal](https://linux-tips.com/letter_avatar_proxy/v4/letter/s/ebca7d/32.png) [@Shailesh\_Paudyal](https://linux-tips.com/u/Shailesh_Paudyal)\
**Post date:** [October 19, 2017, 3:09pm UTC](https://linux-tips.com/t/routing-urls-to-different-backends-in-haproxy/24/2 "2017-10-19T15:09:29Z")

</div>

This looks cool, have you explored what if in the event all the url\_slow backend server are dead, can it fall back to rails\_backend?
