Reputation: 2230
I have 3 ( app-client,app-a, app-b )applications are running in jetty server and one NGINX load balancer ( app-lb). All (internal or external) requests are coming to my application through load balancer. Based on web context ( /app-a/ or /app-b/) name, LB will forward the request to the correct application. I have configured (location /app-a/ and location /app-b and location /app-client) in LB. app-a will call app-b and app-b will call app-a , app-client will be called from outside world, app-client will call app-a or app-b.
I have written Docker-composer for my application. To avoid circular dependency, I have used Docker net. it is working good.
If I scale up my application. LB doesn't know about this new application container.
I have gone though few tutorials and trying to use jwilder/nginx-proxy instead of NGINX. if I use that using VIRTUAL_HOST=app-name variable it is updating upstream in configuration file.But, My application is running based on location mapping for each container.if I don't specify, how request will go to correct container.
How to give location mapping in LB's default.conf file like below since this configuration updated by container dynamically or how to make internal call urls.
location /app-a {
proxy_pass http://app-a;
}
location /app-client {
proxy_pass http://app-client;
}
location /app-b {
proxy_pass http://app-b;
}
Request from outside: http://IP:9090/app-client/
Internal call : http://app-lb:80/app-a/
http://app-lb:80/app-b
LB exposed port no is 9090
Upvotes: 2
Views: 4682
Reputation: 264986
There are pull requests (e.g. #599) for the nginx-proxy image to support virtual paths. To implement this, you can use the original image and just pass your own nginx.tmpl file into the container (as a volume mount, e.g. -v $(pwd)/nginx.tmpl:/app/nginx.tmpl:ro
). Then your containers just need to define VIRTUAL_PATH
as they would VIRTUAL_HOST
.
I'd also recommend setting DEFAULT_HOST
on the nginx-proxy container and have everyone point to that if you don't want hostname based routing.
Note with #599, there's a bug in the nginx.tmpl that I ran into, you need to move {{ $networks := .Networks }}
up two lines to be before the {{ range $container := .Containers }}
(the range redefines .
which redefines .Networks
). Otherwise all networks will be assumed reachable and you'll get timeouts if the container is also attached to other networks that nginx-proxy can't reach.
Upvotes: 3