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.
Comments ( 0 )
No comments available