How to Configure Load balancer in Nginx with Server Weight on centos

To Configure Load balancer in Nginx with Server Weight on CentOS

A load balancer or server load balancer is that which efficiently distributes network or application traffic across a number of servers. With a load balancer, if a server' s performance suffers from excessive traffic or if it stops responding to requests, the load-balancing capabilities will automatically switch the requests to a different server. Load balancers improve the performance of networks and applications by automatically monitoring and managing application and network sessions.

Load Balancer Configuration

First, make sure you make the following configuration.

[root@www ~]# cd /etc/nginx/conf.d/
[root@www conf.d]# vim lb.conf 

upstream backend {
       server 192.168.7.218 
       server 192.168.7.219 

        }

         server {
         listen 80 
         server_name www.linuxhelp1.com 

          location / {
          proxy_pass http://backend 
                     }

         }

After making configurations Save and restart your nginx service. Now, Switch to your browser and provide Machine’ s (load balancer IP or domain name)

Send the request frequently and you will see the changes.

Server weight

Round robin algorithm evenly distributes the request arises from the client side but the backend servers may vary in its specifications. If a server is of high specification we can assign that server to have a higher request that the other with the low specification.
Assigning server weight=3 (say) in one server in the configuration file by,

[root@linuxhelp ~]# vim /etc/nginx/conf.d/lb.conf
upstream backend {
  server 192.168.7.218 
  server 192.168.7.219 weight=3 

    }

  server {
  listen 80 
  server_name www.linuxhelp1.com 

  location / {
  proxy_pass http://backend 
             }

  }

Save and restart the service to make the changes effect and check in your browser. http://www.linuxhelp1.com (load balancer hostname)

Send the request frequently

The differences that you see is, there are 3 connections that go towards your server 2 and by default one goes to server 1.you can verify that by sending the frequent request to the URL it takes three times to move from server 2 to server 1

With this, the method to Configure Load balancer in Nginx with Server Weight comes to an end.


FAQ
Q
Does NGINX Plus support load balancing for mail protocols?
A
Nginx support load balancing for HTTP/HTTPS/FastCGI/uwsgi/SCGI/memcache only. Nginx proxy and route SMTP/POP3/IMAP traffic to a single upstream rather than load-balancing it.
Q
What is thePurpose of using the Nginx?
A
Nginx is an open source high performance Load balancer and web server software. It supports HTTP, HTTPS, SMTP, POP3, and IMAP protocols as a reverse proxy server.
Q
is possible to configure HAProxy Load Balancer in Nginx?
A
Yes, It is possible to load the HAProxy load balancer in the NGiNX.
Q
How can I deploy NGINX Plus for HTTP video?
A
Yes, NGINX Plus is a very popular solution for HTTP video distribution and a great, high-performance, highly scalable, extremely cost-efficient alternative to Wowza or Adobe products.
Q
Is it safe to use the development branch in production in NGiNX?
A
In general, all releases (development or otherwise) are quite stable. This site runs the latest development version at all times. Many NGINX users tend to represent an “early adopter” crowd,