Reverse proxy on Rancher

Hi,
First I wanted to say that I’ve been using rancher for a while and I’m quiet happy about it. Thanx to all the contributors!

I’m still having troubles once in a while though :wink:

The current one is the following:
I would like to create a sort of reverse proxy service (using hte load balancer service) dispatching custom services exposed by rancher. This lb would be running on port 80 in order to be accessible to more people internally. I was intending to do some path routing that is routing request based on whatever was coming after the ‘/’ root.
It works … as long as the target service does not have to load any resources such as css, javascript, images … In which case, it could not find the resource as the hosts are different and the resources path relative the the root host.

I configured an nginx on the target application and tried to configured it so that it would automatically load the resources from the host it should but in vain :frowning:

Any idea how we could tackle this?

Thanx in advance!

There’s no magic solution to this, there’s basically only two choices with a proxy doing path-based routing (and it really has nothing to do with Rancher specifically):

  • The application always returns relative URLs, so the client/browser constructs paths that work regardless of the base path.

or

  • The application is aware of the base path it’s being served from, knows to ignore that part of the path when figuring out what resources to return, and knows to prepend that prefix when constructing new root-relative URLs.

There is some variation in there, e.g. you can have the proxy strip the base path off of the request it sends to the backend, but it has to get back in there on root-relative responses somehow. (In Rancher you can do this with a couple lines in the custom haproxy.cfg)

Or you can try to parse responses from the backend and rewrite all the paths, but that is an error-prone game.

…or use different or sub-domains and eliminate the problem entirely…

Nothing to do with Rancher indeed.
A simple change in the configuration build of the target application to change the href base did the trick.

Thank you!