betwar512
betwar512

Reputation: 33

Using multiple Docker Nginx load balancer behind another Nginx load balancer , is this consider as a bad practice?

I have one dev/Experimental server in our company, base of our projects is mainly java web apps, so when I want it to move our projects to Docker and scale horizontally to test our stateless servers, I did create docker-compose for each project with their own Nginx load balancer. As a result, I end up with 6 scalable projects and each with one Nginx, so I attached all Nginx to a same network and created main Nginx that attaches to port 80 of host and balance between all the running Nginx.

Problem: I was facing an issue with defined upstream as it was requiring the service to be up and sometimes some of projects were under maintenance and causing Nginx to crash.

Solution: adding seperate Nginx behind my main Nginx helped to run each project whenever I want and use only variable names in Nginx proxy pass so in case of upstream for any java project is down I still be able to run main Nginx.

Each nginx has block of

upstream mydocker-service{
  ...
}

and main Nginx contains multiple

set $stream mydocker-service;

used as proxy_pass.

at the end I end up with 6 Nginx responsible for upstream of each project and main Nginx responsible for redirecting request to each Nginx as proxy_pass.

Our projects are not Spring and is not possible to move to Spring either.

So my question is , this consider as a bad practice , am I doing it a right way? I there any better solution I can use without going overhead and do kubernetes as I only have one instance?

Upvotes: 0

Views: 722

Answers (1)

Carlos
Carlos

Reputation: 1806

If I'm understanding what you want correctly, you should probably make a 1 node swarm. Swarm will provide the load balancing of your scaled services and you would not need an nginx instance for each project. To enable swarm all you need is to run docker swarm init then you would use docker stack deploy -c yourcomposefile.yml yourstackname to deploy your services. To scale your services you can either use the replicas setting in your compose file or run the docker service scale yourservicename=3(to scale your service to 3 replicas).

Upvotes: 1

Related Questions