# Load Balancer to redirect to apps

**URL:** <https://forums.suse.com/t/load-balancer-to-redirect-to-apps/397>\
**Category:** Rancher 1.x\
**Created:** [September 3, 2015, 8:20pm UTC](https://forums.suse.com/t/load-balancer-to-redirect-to-apps/397 "2015-09-03T20:20:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![uuunk](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/uuunk/32/194_2.png) [@uuunk](https://forums.suse.com/u/uuunk)\
**Post date:** [September 3, 2015, 8:20pm UTC](https://forums.suse.com/t/load-balancer-to-redirect-to-apps/397/1 "2015-09-03T20:20:14Z")

</div>

I’m trying to use a load balancer to redirect based on path to different apps. For example, I’d like  
`example.com/app1` to forward to a stack or service called app1. The problem is the request path is being passed along with the forwarding request. So app1 hosted at `192.168.0.5` gets a request of `192.168.0.5/app1`. From what I understand of HAProxy, I could do this in the config with `reqrep`

```
backend app1_backend
   reqrep ^([^\ :]*)\ /app1/(.*) \1\ /\2
   server app1 rancher_private_IP:80

```

Is there a different way to do this in Rancher?

---

<div class="post-metadata">

**Author:** ![vincent](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/vincent/32/7156_2.png) [@vincent](https://forums.suse.com/u/vincent)\
**Post date:** [September 3, 2015, 8:47pm UTC](https://forums.suse.com/t/load-balancer-to-redirect-to-apps/397/2 "2015-09-03T20:47:26Z")

</div>

There is not currently a way to do this. We’re considering a way to let you add custom haproxy config in [#1871](https://github.com/rancher/rancher/issues/1871).

What you describe can’t be the default configuration because it won’t work right if the application returns any absolute or root-relative links/CSS includes/other things, which is pretty common. So alternately you configure the application to know that it is running from the base url `/app1` instead of `/`.

---

<div class="post-metadata">

**Author:** ![uuunk](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/uuunk/32/194_2.png) [@uuunk](https://forums.suse.com/u/uuunk)\
**Post date:** [September 3, 2015, 10:08pm UTC](https://forums.suse.com/t/load-balancer-to-redirect-to-apps/397/3 "2015-09-03T22:08:39Z")

</div>

Ah that makes sense. I suppose the best way to do it then would be to forward based on subdomain (`app1.example.com`) if possible.

---

<div class="post-metadata">

**Author:** ![vincent](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/vincent/32/7156_2.png) [@vincent](https://forums.suse.com/u/vincent)\
**Post date:** [September 3, 2015, 10:20pm UTC](https://forums.suse.com/t/load-balancer-to-redirect-to-apps/397/4 "2015-09-03T22:20:25Z")

</div>

Yup, and you can do hostname-based routing today.

---

<div class="post-metadata">

**Author:** ![virtuman](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/virtuman/32/1046_2.png) [@virtuman](https://forums.suse.com/u/virtuman)\
**Post date:** [April 23, 2016, 12:59am UTC](https://forums.suse.com/t/load-balancer-to-redirect-to-apps/397/5 "2016-04-23T00:59:09Z")

</div>

and is there a way to make a global match based on subdomain?  
ie:

[chat.domain.com:80](http://chat.domain.com:80) =\> container \>\> chat port 80  
[branch1.domain.com:80](http://branch1.domain.com:80) =\> container \>\> deployed branch1 port 80

so instead of having to manually specify the subdomain to container mapping, is it possible to setup a global subdomain match to container name, and if such container exists and has this specific port open then serve content from it

Even better - there’s a great project on github by jwilder/nginx-proxy - it basically looks for any container that has  
VIRTUAL\_HOST=[www.domain.com](http://www.domain.com) and optionally VIRTUAL\_PORT=3333  
if any container on the network exists with these environment varaibles - then it auto-magically updated nginx.conf to create virtual hosts with SSL support.  
Is it possible to achieve similar behavior through Rancher or can this functionality be added?

Thank you

---

<div class="post-metadata">

**Author:** ![denise](https://avatars.discourse-cdn.com/v4/letter/d/82dd89/32.png) [@denise](https://forums.suse.com/u/denise)\
**Post date:** [May 3, 2016, 8:56pm UTC](https://forums.suse.com/t/load-balancer-to-redirect-to-apps/397/6 "2016-05-03T20:56:21Z")

</div>

@virtuman Currently, this functionality doesn’t exist. You can file an enhancement request in Github for your use case.
