HTTP Load Balancing

Before proceeding towards load balancing first we need to define the upstream directive in our configuration file.

For the demo purpose we will be using round robin load balancing type, to proceed further you must have to setup proxy pass in two servers for load balancing. For knowing how to setup reverse proxy please follow previous topic which says configuring nginx reverse proxy.

Once you are done create an nginx load balancing config with upstream directive as mentioned below

upstream backend {
	server <server 1 ip>;
	server <server 2 ip>;
}
server {
	listen 80;
        server_name _;
	location / {
		proxy_pass http://backend;
	}
}

Copy the above code and paste it in your nginx working directory, after that test your nginx configuration with

sudo nginx -t

If successful then restart your nginx by

sudo service nginx restart

After that hit you load balancing ip or dns on browser and hit refresh and see the load getting balanced.
You can also hit multiple curl on the load balancing server

curl http://localhost
Subscribe Now