Member-only story
Setting Up Two Node.js Containers and an NGINX Load Balancer Using Docker
Easy way to setup a load balancer with docker and nginx
Docker is playing an important role in web application deployment nowadays. Today we will see how to use Docker to create two Node.js application containers and an NGINX load balancer container to distribute the load between them.
How will this load balancer work?
First, we will create two Node.js servers, and then we will use NGINX to create a load balancer. This load balancer will distribute the load between our Node.js servers. When a user sends a request, NGINX will distribute those requests between the Node.js servers.
Node.js Application:
Our Node.js application is very simple. It will return a response when a request is received on the server, showing which container is serving the request. Since each Node.js server runs on a different hostname/container, when a request is sent from the NGINX server, the Node.js server will return the time of the request, the user’s IP address, and the hostname of the server handling the request.