# Haproxy redirect multiple webserver

**URL:** <https://discourse.haproxy.org/t/haproxy-redirect-multiple-webserver/3743>\
**Category:** Help!\
**Created:** [April 18, 2019, 4:01pm UTC](https://discourse.haproxy.org/t/haproxy-redirect-multiple-webserver/3743 "2019-04-18T16:01:18Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![smangiagli](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@smangiagli](https://discourse.haproxy.org/u/smangiagli)\
**Post date:** [April 18, 2019, 4:01pm UTC](https://discourse.haproxy.org/t/haproxy-redirect-multiple-webserver/3743/1 "2019-04-18T16:01:18Z")

</div>

Hi all,

I’m looking for a possible configuration for haproxy to redirect http requests to multiple web servers. In particular, if the request is [http://193.206.112.10](http://193.206.112.10) it is diverted to the 10.200.1.1 and 10.200.1.2 servers, if the http request is [http://193.206.112.10/test](http://193.206.112.10/test) it is diverted to the server 10.200.1.3

---

<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:** [April 21, 2019, 7:20am UTC](https://discourse.haproxy.org/t/haproxy-redirect-multiple-webserver/3743/2 "2019-04-21T07:20:34Z")

</div>

Just define two backends, the first one with the two servers, and a second one for the third server. Then just use ACL’s based on the [path](http://cbonte.github.io/haproxy-dconv/1.8/configuration.html#path) sample to [use\_backend](http://cbonte.github.io/haproxy-dconv/1.8/configuration.html#4-use_backend) the proper one.

---

<div class="post-metadata">

**Author:** ![smangiagli](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@smangiagli](https://discourse.haproxy.org/u/smangiagli)\
**Post date:** [April 24, 2019, 2:27pm UTC](https://discourse.haproxy.org/t/haproxy-redirect-multiple-webserver/3743/3 "2019-04-24T14:27:56Z")

</div>

I didn’t understand how to do it, could you tell me how to do it? Sorry but I’m not very good with ACL

---

<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:** [April 25, 2019, 6:37am UTC](https://discourse.haproxy.org/t/haproxy-redirect-multiple-webserver/3743/4 "2019-04-25T06:37:51Z")

</div>

If you only have two conditions i.e if the path is /test, use one backend else use the other, it can be achieved as:

> acl is\_test path -i -m beg /test  
> use\_backend be\_test if is\_test

This is using the acl is\_test if the URL path is beginning with /test. If this condition is true, it will select the be\_test backend where you can put the 10.200.1.3 server as backend. Otherwise, the default backend will be selected where the backend servers are 10.200.1.1 and 10.200.1.2

---

<div class="post-metadata">

**Author:** ![smangiagli](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@smangiagli](https://discourse.haproxy.org/u/smangiagli)\
**Post date:** [April 25, 2019, 1:25pm UTC](https://discourse.haproxy.org/t/haproxy-redirect-multiple-webserver/3743/5 "2019-04-25T13:25:48Z")

</div>

Ok I try this solution. Thx

---

<div class="post-metadata">

**Author:** ![smangiagli](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@smangiagli](https://discourse.haproxy.org/u/smangiagli)\
**Post date:** [April 25, 2019, 2:40pm UTC](https://discourse.haproxy.org/t/haproxy-redirect-multiple-webserver/3743/6 "2019-04-25T14:40:22Z")

</div>

This is my haproxy.cfg, but

> frontend Local\_Server  
> bind \*:80  
> mode http  
> option httplog  
> option http-server-close  
> acl is\_admin path\_beg -i /administrator  
> redirect prefix [http://172.22.80.16](http://172.22.80.16) if is\_admin  
> acl is\_ufsoit path -i -m beg /ufsoit  
> use\_backend be\_ufsoit if is\_ufsoit  
> default\_backend My\_Web\_Servers

> backend My\_Web\_Servers  
> mode http  
> balance roundrobin  
> option forwardfor  
> http-request set-header X-Forwarded-Port %[dst\_port]  
> http-request add-header X-Forwarded-Proto https if { ssl\_fc }  
> option httpchk HEAD / HTTP/1.1rnHost:localhost  
> server web1 172.22.80.17:80  
> server web2 172.22.80.18:80  
> server web3 172.22.80.19:80

> backend be\_ufsoit  
> mode http  
> balance roundrobin  
> option forwardfor  
> http-request set-header X-Forwarded-Port %[dst\_port]  
> http-request add-header X-Forwarded-Proto https if { ssl\_fc }  
> option httpchk HEAD / HTTP/1.1rnHost:localhost  
> server web4 172.22.80.20:80

When i call http://my\_name\_server/ufosit an error occur.  
I think because in the server 172.22.80.20 there is no subdirectory called ufsoit

---

<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:** [April 25, 2019, 4:40pm UTC](https://discourse.haproxy.org/t/haproxy-redirect-multiple-webserver/3743/7 "2019-04-25T16:40:39Z")

</div>

What is the error?

---

<div class="post-metadata">

**Author:** ![smangiagli](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@smangiagli](https://discourse.haproxy.org/u/smangiagli)\
**Post date:** [April 26, 2019, 9:58am UTC](https://discourse.haproxy.org/t/haproxy-redirect-multiple-webserver/3743/8 "2019-04-26T09:58:28Z")

</div>

Page not found 404

---

<div class="post-metadata">

**Author:** ![smangiagli](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@smangiagli](https://discourse.haproxy.org/u/smangiagli)\
**Post date:** [April 30, 2019, 9:32am UTC](https://discourse.haproxy.org/t/haproxy-redirect-multiple-webserver/3743/9 "2019-04-30T09:32:34Z")

</div>

Any suggest?

---

<div class="post-metadata">

**Author:** ![supermathie](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.haproxy.org/supermathie/32/373_2.png) [@supermathie](https://discourse.haproxy.org/u/supermathie)\
**Post date:** [April 30, 2019, 10:32pm UTC](https://discourse.haproxy.org/t/haproxy-redirect-multiple-webserver/3743/10 "2019-04-30T22:32:11Z")

</div>

> [@smangiagli](#):
>
> I think because in the server 172.22.80.20 there is no subdirectory called ufsoit

So you need to strip off the first part of the path in the `be_ufsoit` backend?

Try this:

```plaintext
backend be_ufsoit
  …
  reqrep "^([^ :]*) /ufsoit/(.*)" "\1 /\2"

```

---

<div class="post-metadata">

**Author:** ![smangiagli](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@smangiagli](https://discourse.haproxy.org/u/smangiagli)\
**Post date:** [May 2, 2019, 1:36am UTC](https://discourse.haproxy.org/t/haproxy-redirect-multiple-webserver/3743/11 "2019-05-02T01:36:32Z")

</div>

I used the following rule and the routing works correctly to the right server.

```auto
reqrep ^([^\]*\ /)web1[/]?(.*) \1\2

```

But the page is loaded without a style sheet and images

---

<div class="post-metadata">

**Author:** ![supermathie](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.haproxy.org/supermathie/32/373_2.png) [@supermathie](https://discourse.haproxy.org/u/supermathie)\
**Post date:** [May 2, 2019, 1:39am UTC](https://discourse.haproxy.org/t/haproxy-redirect-multiple-webserver/3743/12 "2019-05-02T01:39:23Z")

</div>

Having seen much pain with subfolder setups like this, you are in for a world of hurt if the backend isn’t expecting traffic at that subfolder because it’s probably sending back links to assets at /, not /ufsoit/
