2

I'm trying to setup multiple docker containers with the same image on a single machine and hosting all the application on the same domain separated by path. The purpose is to isolate each customers into it's own container. i.e. mydomain.com/aaa, mydomain.com/bbb ... etc.

I'm using nginx as the reverse proxy and followed various example online. My nginx configuration looks like:

server {
    listen       ...;
    ...
    location / {
        proxy_pass http://127.0.0.1:8080;
    }

    location /aaa {
        proxy_pass http://127.0.0.1:8181;
    }

    location /bbb {
        proxy_pass http://127.0.0.1:8282;
    }
    ...
}

I noticed that the application is expecting to be hosted on the root / which currently end up in 404. Is there a clever way to rewrite those into it's own path based on the origin of the request without modifying the application itself?

I'm aware that it might be easier to use sub-domain but I want to avoid adding and removing sub-domain as customers come and go.

faulty
  • 235
  • 1
  • 4
  • 14

2 Answers2

3

The simple answer is no.

You need to consider at least three aspects of forcing an application to live away from the root.

  • Mapping root based URLs to the new location - which is easy with proxy_pass or a rewrite
  • Mapping redirection responses (301, 302, etc) - which is easy with proxy_redirect
  • Mapping resource URLs and embedded hyperlinks

The last point is not easy. Applications which expect to live in the root, generally access their resources relative to the root, which means they hit the wrong location in the reverse proxy.

Apache has a module which can rewrite URLs embedded within the HTML document, but that seems rather inefficient to me.

The preferred solution is to change the application to make its resource and hyperlink URLs either path relative or prefixed with the same custom path.

Richard Smith
  • 12,834
  • 2
  • 21
  • 29
0

I'm trying to do the same setup, so I've run into the same problem. Seems to me that one actually has to change the backend applications as Richard Smith describes it. Using different "outside" ports for nginx is a workaround, but it's not an elegant one.

Karl Auer
  • 11
  • 3
  • I think Richard Smith is referring to using the same custom path or "subdirectory" as configured in nginx, not ports – faulty Mar 29 '16 at 00:30