Load Balancer to redirect to apps

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?

1 Like

There is not currently a way to do this. We’re considering a way to let you add custom haproxy config in #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 /.

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.

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

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

chat.domain.com:80 => container >> chat port 80
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 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

1 Like

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