SlideShare a Scribd company logo
1 of 7
Download to read offline
How To Configure Load Balancer Nginx on CentOS 7
i | P a g e
Table of Contents
Overview.......................................................................................................................................................1
Applies To......................................................................................................................................................1
Pre-Requisites ...............................................................................................................................................1
Package Install – nginx..................................................................................................................................1
Package Install – Verify .............................................................................................................................2
Enable Service - nginx ...............................................................................................................................2
Configure – nginx ..........................................................................................................................................2
Configure Nginx – Load Balancer..............................................................................................................2
Configuration – Overview.........................................................................................................................2
Configuration – Server Directive – Node 1 and Node 2............................................................................3
Configuration – Server Directive – Load Balancer Node...........................................................................4
Upstream Section – Load Balancer...........................................................................................................5
Load Balancer Customization Table..........................................................................................................5
Testing – Load Balancer ............................................................................................................................6
Testing - Curl Utility...............................................................................................................................6
Testing – Web Browser.........................................................................................................................6
How To Configure Load Balancer Nginx on CentOS 7
1 | P a g e
Overview
Nginx is an open-source, high performance HTTP & ReverseProxy Server, it can also be configured to
operate as IMAP / POP3 Server.
It’s well-known for high performance, stability, rich feature set, simple configuration and low resource
consumption.
In this guide we will configure nginx server to run as a load-balancer on a Linux based operating system.
Applies To
 CentOS 7, tested on CentOS Linux release 7.1.1503 (Core)
Pre-Requisites
1) 3 Servers nginx installed, enabled and started;
a) 1 server acts as load balancer server.
b) 2 server(s) acts as webserver also acts as LB Node 1 and LB Node 2.
2) epel-release repository is installed on the server.
a) If epel repository is not installed, to install run the command; yum install epel-release -y -q
Package Install – nginx
After installing “epel-release” repository package; install nginx package, run the command;
yum install nginx -y
How To Configure Load Balancer Nginx on CentOS 7
2 | P a g e
Package Install – Verify
After installation of nginx package, to confirm if the package has been successfully installed, you can run
the command;
yum list installed | grep nginx or
rpm -qai screen | grep -E "Name| Install Date"
Enable Service - nginx
After installation of nginx package, next step is to configure nginx service daemon to automatically start
upon server reboots. To start service automatically, run the command;
systemctl enable nginx
Configure – nginx
By default nginx is preconfigured, if you intend to customize server parameters this can be accomplished
by editing the master configuration file “/etc/nginx/nginx.conf” in “server” block section.
By default port “80” is the configured for nginx service to “LISTEN”, and when the server is started, server
starts automatically on IPV4 and IPV6 network interface(s).
Configure Nginx – Load Balancer
First step, for configuring Nginx as load balancer, each node (webserver) has to be configured to serve
webpage. Once you install, configure, enable and start nginx service. Ensure that default page load’s
correctly; execute the command, this command should fetch the default webpage “index.html”.
curl localhost
Configuration – Overview
In this section we will configure load balancer, to configure it we need below servers, you can add more
servers if the work loads are higher. Below table give a typical 2 node webserver and a load balancer.
Server Function Hostname
Web Server Node #1 vcptest01
Web Server Node #2 vcptest01
Load Balancer Node vcplbsrvr
How To Configure Load Balancer Nginx on CentOS 7
3 | P a g e
Configuration – Server Directive – Node 1 and Node 2
Next step in load balancer configuration is to configure “server” block, again if there is any specific
business requirement. Default configuration is good enough, default configuration for “server” block
snippet is posted below.
vi /etc/nginx/nginx.conf
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
How To Configure Load Balancer Nginx on CentOS 7
4 | P a g e
Configuration – Server Directive – Load Balancer Node
Configuring Load balancer on Nginx is quite simple; create a new configuration file “load-balancer.conf”
in the folder “/etc/nginx/conf.d/”, and copy and paste the below configuration snippet.
vi /etc/ngnix/conf.d/load-balancer.conf
upstream websrvrlb {
server vcptest01;
server vcptest02;
}
server {
listen 80;
location / {
proxy_pass http://websrvrlb;
}
}
How To Configure Load Balancer Nginx on CentOS 7
5 | P a g e
Upstream Section – Load Balancer
Upstream block has few directives that needs to be configured, so that load balancer can work effectively
and efficiently.
Directive Purpose
upstream websrvrlb The servers that Nginx proxies requests to are known as upstream
servers.
server vcptest01; Define load balancer node, define one node per line.
server vcptest02 down; Define host failed state; if any of the participating node is down for
maintenance or hardware failure, set the node value “down”.
listen 80; Define webserver’s Listen port.
location / Define location of files to serve from.
proxy_pass http://websrvrlb Define proxy server originating from specific IP Address and port, for
load balancer, it is associated with upstream defined name.
Load Balancer Customization Table
Nginx load balancer can be customized based on the business need. This directive has to be defined inside
upstream block.
Load balancer method should be determined and configured based on server performance, network
latency, network path, connectivity time.
LB Method Directive Description
Round
Robin
No Directive It’s default LB method; wherein requests are distributed equally
across the servers it also takes into consideration the server weights.
Least
Connection
least_conn; Request is sent to least number of current active connections, this
methods also takes into consideration the server weights.
IP Hash ip_hash; It can also as called sticky session server binding, it sends to request
to same server, unless the requested server is not available.
Hash hash; The server to which a request is sent is determined from a user-
defined key which may be a text, variable, or their combination.
Least Time least_time; Selects the server with the lowest average latency and the least
number of active connections, this option is available for Nginx Plus
version.
How To Configure Load Balancer Nginx on CentOS 7
6 | P a g e
Testing – Load Balancer
Once the load balancer is configured, after restarting the service, you can test them 2 methods;
1) Web Browser
2) Command Line Interface (CLI using curl utility)
Testing - Curl Utility
The below screen shot is shown the request processed on bash shell prompt, when the each time the
request is made, request is fetched from alternate webserver i.e., vcptest01 and vcptest02 .
curl localhost
Testing – Web Browser
The below screenshot is shown the request processed on web browser, when the each time the request
is made, request is fetched from alternate webserver i.e., vcptest01 and vcptest02.
Refresh the browser

More Related Content

What's hot

What's hot (20)

VM Autoscaling With CloudStack VR As Network Provider
VM Autoscaling With CloudStack VR As Network ProviderVM Autoscaling With CloudStack VR As Network Provider
VM Autoscaling With CloudStack VR As Network Provider
 
Spring cloud on kubernetes
Spring cloud on kubernetesSpring cloud on kubernetes
Spring cloud on kubernetes
 
VMware Advance Troubleshooting Workshop - Day 3
VMware Advance Troubleshooting Workshop - Day 3VMware Advance Troubleshooting Workshop - Day 3
VMware Advance Troubleshooting Workshop - Day 3
 
Maria db 이중화구성_고민하기
Maria db 이중화구성_고민하기Maria db 이중화구성_고민하기
Maria db 이중화구성_고민하기
 
[2018] 오픈스택 5년 운영의 경험
[2018] 오픈스택 5년 운영의 경험[2018] 오픈스택 5년 운영의 경험
[2018] 오픈스택 5년 운영의 경험
 
Ceph issue 해결 사례
Ceph issue 해결 사례Ceph issue 해결 사례
Ceph issue 해결 사례
 
MySQL 상태 메시지 분석 및 활용
MySQL 상태 메시지 분석 및 활용MySQL 상태 메시지 분석 및 활용
MySQL 상태 메시지 분석 및 활용
 
HPE SimpliVity 升級 4.1.0
HPE SimpliVity 升級 4.1.0HPE SimpliVity 升級 4.1.0
HPE SimpliVity 升級 4.1.0
 
Step by Step Restore rman to different host
Step by Step Restore rman to different hostStep by Step Restore rman to different host
Step by Step Restore rman to different host
 
IT Automation with Ansible
IT Automation with AnsibleIT Automation with Ansible
IT Automation with Ansible
 
MariaDB 제품 소개
MariaDB 제품 소개MariaDB 제품 소개
MariaDB 제품 소개
 
Terraform Introduction
Terraform IntroductionTerraform Introduction
Terraform Introduction
 
Nginx Reverse Proxy with Kafka.pptx
Nginx Reverse Proxy with Kafka.pptxNginx Reverse Proxy with Kafka.pptx
Nginx Reverse Proxy with Kafka.pptx
 
Cloud stack vs openstack vs eucalyptus
Cloud stack vs openstack vs eucalyptusCloud stack vs openstack vs eucalyptus
Cloud stack vs openstack vs eucalyptus
 
Oracle Enterprise Manager Seven Robust Features to Put in Action final
Oracle Enterprise Manager Seven Robust Features to Put in Action finalOracle Enterprise Manager Seven Robust Features to Put in Action final
Oracle Enterprise Manager Seven Robust Features to Put in Action final
 
Docker Networking Deep Dive
Docker Networking Deep DiveDocker Networking Deep Dive
Docker Networking Deep Dive
 
Building a redundant CloudStack management cluster - Vladimir Melnik
Building a redundant CloudStack management cluster - Vladimir MelnikBuilding a redundant CloudStack management cluster - Vladimir Melnik
Building a redundant CloudStack management cluster - Vladimir Melnik
 
Deep Dive on Amazon EC2 Instances & Performance Optimization Best Practices (...
Deep Dive on Amazon EC2 Instances & Performance Optimization Best Practices (...Deep Dive on Amazon EC2 Instances & Performance Optimization Best Practices (...
Deep Dive on Amazon EC2 Instances & Performance Optimization Best Practices (...
 
[오픈소스컨설팅]쿠버네티스를 활용한 개발환경 구축
[오픈소스컨설팅]쿠버네티스를 활용한 개발환경 구축[오픈소스컨설팅]쿠버네티스를 활용한 개발환경 구축
[오픈소스컨설팅]쿠버네티스를 활용한 개발환경 구축
 
HPE SimpliVity install mgmt guide 201907-01 (Taiwan-Chinese) ;HPE SimpliVity ...
HPE SimpliVity install mgmt guide 201907-01 (Taiwan-Chinese) ;HPE SimpliVity ...HPE SimpliVity install mgmt guide 201907-01 (Taiwan-Chinese) ;HPE SimpliVity ...
HPE SimpliVity install mgmt guide 201907-01 (Taiwan-Chinese) ;HPE SimpliVity ...
 

Viewers also liked

Viewers also liked (20)

How To Install and Configure Salt Master on Ubuntu
How To Install and Configure Salt Master on UbuntuHow To Install and Configure Salt Master on Ubuntu
How To Install and Configure Salt Master on Ubuntu
 
How To Check IE Enhanced Security Is Enabled Windows PowerShell
How To Check IE Enhanced Security Is Enabled Windows PowerShellHow To Check IE Enhanced Security Is Enabled Windows PowerShell
How To Check IE Enhanced Security Is Enabled Windows PowerShell
 
How To Disable IE Enhanced Security Windows PowerShell
How To Disable IE Enhanced Security Windows PowerShellHow To Disable IE Enhanced Security Windows PowerShell
How To Disable IE Enhanced Security Windows PowerShell
 
How To Protect SSH Access with Fail2Ban on RHEL 7
How To Protect SSH Access with Fail2Ban on RHEL 7How To Protect SSH Access with Fail2Ban on RHEL 7
How To Protect SSH Access with Fail2Ban on RHEL 7
 
How To Configure SNMP Logging on RHEL 7
How To Configure SNMP Logging on RHEL 7How To Configure SNMP Logging on RHEL 7
How To Configure SNMP Logging on RHEL 7
 
Nginx bind() to 0.0.0.0:9080 failed
Nginx bind() to 0.0.0.0:9080 failedNginx bind() to 0.0.0.0:9080 failed
Nginx bind() to 0.0.0.0:9080 failed
 
How To Install and Configure Screen on CentOS 7
How To Install and Configure Screen on CentOS 7How To Install and Configure Screen on CentOS 7
How To Install and Configure Screen on CentOS 7
 
How To Install and Configure SNMP on RHEL 7 or CentOS 7
How To Install and Configure SNMP on RHEL 7 or CentOS 7How To Install and Configure SNMP on RHEL 7 or CentOS 7
How To Install and Configure SNMP on RHEL 7 or CentOS 7
 
How To Install and Configure AWS CLI on RHEL 7
How To Install and Configure AWS CLI on RHEL 7How To Install and Configure AWS CLI on RHEL 7
How To Install and Configure AWS CLI on RHEL 7
 
Install telnet Linux
Install telnet LinuxInstall telnet Linux
Install telnet Linux
 
How To Install and Configure Log Rotation on RHEL 7 or CentOS 7
How To Install and Configure Log Rotation on RHEL 7 or CentOS 7How To Install and Configure Log Rotation on RHEL 7 or CentOS 7
How To Install and Configure Log Rotation on RHEL 7 or CentOS 7
 
LSOF Command Usage on RHEL 7
LSOF Command Usage on RHEL 7LSOF Command Usage on RHEL 7
LSOF Command Usage on RHEL 7
 
How To Configure Apache VirtualHost on RHEL 7 on AWS
How To Configure Apache VirtualHost on RHEL 7 on AWSHow To Configure Apache VirtualHost on RHEL 7 on AWS
How To Configure Apache VirtualHost on RHEL 7 on AWS
 
How to Install Configure and Use sysstat utils on RHEL 7
How to Install Configure and Use sysstat utils on RHEL 7How to Install Configure and Use sysstat utils on RHEL 7
How to Install Configure and Use sysstat utils on RHEL 7
 
How To Install OpenFire in CentOS 7
How To Install OpenFire in CentOS 7How To Install OpenFire in CentOS 7
How To Install OpenFire in CentOS 7
 
How To View Login History and Logout History on RHEL 7
How To View Login History and Logout History on RHEL 7How To View Login History and Logout History on RHEL 7
How To View Login History and Logout History on RHEL 7
 
Batch script for nslookup range of ip address
Batch script for nslookup range of ip addressBatch script for nslookup range of ip address
Batch script for nslookup range of ip address
 
Install and Configure RSyslog – CentOS 7 / RHEL 7
Install and Configure RSyslog – CentOS 7 / RHEL 7Install and Configure RSyslog – CentOS 7 / RHEL 7
Install and Configure RSyslog – CentOS 7 / RHEL 7
 
Red Hat Satellite 6 - Automation with Puppet
Red Hat Satellite 6 - Automation with PuppetRed Hat Satellite 6 - Automation with Puppet
Red Hat Satellite 6 - Automation with Puppet
 
How to Configure OpenFiler for NFS Share
How to Configure OpenFiler for NFS ShareHow to Configure OpenFiler for NFS Share
How to Configure OpenFiler for NFS Share
 

Similar to How To Configure Nginx Load Balancer on CentOS 7

How to configure amazon ec2 load balancer
How to configure amazon ec2 load balancerHow to configure amazon ec2 load balancer
How to configure amazon ec2 load balancer
VCP Muthukrishna
 
WSO2 Dep Sync for Artifact Synchronization of Cluster Nodes
WSO2 Dep Sync for Artifact Synchronization of Cluster NodesWSO2 Dep Sync for Artifact Synchronization of Cluster Nodes
WSO2 Dep Sync for Artifact Synchronization of Cluster Nodes
WSO2
 
[WSO2] Deployment Synchronizer for Deployment Artifact Synchronization Betwee...
[WSO2] Deployment Synchronizer for Deployment Artifact Synchronization Betwee...[WSO2] Deployment Synchronizer for Deployment Artifact Synchronization Betwee...
[WSO2] Deployment Synchronizer for Deployment Artifact Synchronization Betwee...
Kasun Gajasinghe
 
Sa106 – practical solutions for connections administrators
Sa106 – practical solutions for connections administratorsSa106 – practical solutions for connections administrators
Sa106 – practical solutions for connections administrators
Sharon James
 
Netxms install guide
Netxms install guideNetxms install guide
Netxms install guide
Naga Raju N
 

Similar to How To Configure Nginx Load Balancer on CentOS 7 (20)

How to configure amazon ec2 load balancer
How to configure amazon ec2 load balancerHow to configure amazon ec2 load balancer
How to configure amazon ec2 load balancer
 
How To Configure VNC Server on CentOS 7
How To Configure VNC Server on CentOS 7How To Configure VNC Server on CentOS 7
How To Configure VNC Server on CentOS 7
 
WSO2 Dep Sync for Artifact Synchronization of Cluster Nodes
WSO2 Dep Sync for Artifact Synchronization of Cluster NodesWSO2 Dep Sync for Artifact Synchronization of Cluster Nodes
WSO2 Dep Sync for Artifact Synchronization of Cluster Nodes
 
[WSO2] Deployment Synchronizer for Deployment Artifact Synchronization Betwee...
[WSO2] Deployment Synchronizer for Deployment Artifact Synchronization Betwee...[WSO2] Deployment Synchronizer for Deployment Artifact Synchronization Betwee...
[WSO2] Deployment Synchronizer for Deployment Artifact Synchronization Betwee...
 
How To Configure Amazon EC2 Load Balancer
How To Configure Amazon EC2 Load BalancerHow To Configure Amazon EC2 Load Balancer
How To Configure Amazon EC2 Load Balancer
 
How To Setup Highly Available Web Servers with Keepalived & Floating IPs on U...
How To Setup Highly Available Web Servers with Keepalived & Floating IPs on U...How To Setup Highly Available Web Servers with Keepalived & Floating IPs on U...
How To Setup Highly Available Web Servers with Keepalived & Floating IPs on U...
 
ITB2019 NGINX Overview and Technical Aspects - Kevin Jones
ITB2019 NGINX Overview and Technical Aspects - Kevin JonesITB2019 NGINX Overview and Technical Aspects - Kevin Jones
ITB2019 NGINX Overview and Technical Aspects - Kevin Jones
 
Load Balancer Device and Configurations.
Load Balancer Device and Configurations.Load Balancer Device and Configurations.
Load Balancer Device and Configurations.
 
Practical solutions for connections administrators
Practical solutions for connections administratorsPractical solutions for connections administrators
Practical solutions for connections administrators
 
How to installation and configure apache2
How to installation and configure apache2How to installation and configure apache2
How to installation and configure apache2
 
NGINX: Basics and Best Practices
NGINX: Basics and Best PracticesNGINX: Basics and Best Practices
NGINX: Basics and Best Practices
 
Install and Configure WordPress in AWS on RHEL 7 or CentOS 7
Install and Configure WordPress in AWS on RHEL 7 or CentOS 7Install and Configure WordPress in AWS on RHEL 7 or CentOS 7
Install and Configure WordPress in AWS on RHEL 7 or CentOS 7
 
NGINX: Basics & Best Practices - EMEA Broadcast
NGINX: Basics & Best Practices - EMEA BroadcastNGINX: Basics & Best Practices - EMEA Broadcast
NGINX: Basics & Best Practices - EMEA Broadcast
 
Install nginx on ubuntu 21.04 server
Install nginx on ubuntu 21.04 serverInstall nginx on ubuntu 21.04 server
Install nginx on ubuntu 21.04 server
 
How To Install and Configure Apache SSL on CentOS 7
How To Install and Configure Apache SSL on CentOS 7How To Install and Configure Apache SSL on CentOS 7
How To Install and Configure Apache SSL on CentOS 7
 
Installing lemp with ssl and varnish on Debian 9
Installing lemp with ssl and varnish on Debian 9Installing lemp with ssl and varnish on Debian 9
Installing lemp with ssl and varnish on Debian 9
 
Sa106 – practical solutions for connections administrators
Sa106 – practical solutions for connections administratorsSa106 – practical solutions for connections administrators
Sa106 – practical solutions for connections administrators
 
NGINX ADC: Basics and Best Practices – EMEA
NGINX ADC: Basics and Best Practices – EMEANGINX ADC: Basics and Best Practices – EMEA
NGINX ADC: Basics and Best Practices – EMEA
 
Netxms install guide
Netxms install guideNetxms install guide
Netxms install guide
 
How to install and configure LEMP stack
How to install and configure LEMP stackHow to install and configure LEMP stack
How to install and configure LEMP stack
 

More from VCP Muthukrishna

More from VCP Muthukrishna (20)

How to Fix Duplicate Packages in YUM on CentOS 7
How to Fix Duplicate Packages in YUM on CentOS 7How to Fix Duplicate Packages in YUM on CentOS 7
How to Fix Duplicate Packages in YUM on CentOS 7
 
How To Install and Configure GNome on CentOS 7
How To Install and Configure GNome on CentOS 7How To Install and Configure GNome on CentOS 7
How To Install and Configure GNome on CentOS 7
 
How To Connect to Active Directory User Validation
How To Connect to Active Directory User ValidationHow To Connect to Active Directory User Validation
How To Connect to Active Directory User Validation
 
How To Connect To Active Directory PowerShell
How To Connect To Active Directory PowerShellHow To Connect To Active Directory PowerShell
How To Connect To Active Directory PowerShell
 
How To List Files on Remote Server - PowerShell
How To List Files on Remote Server - PowerShellHow To List Files on Remote Server - PowerShell
How To List Files on Remote Server - PowerShell
 
How To List Files and Display In HTML Format
How To List Files and Display In HTML FormatHow To List Files and Display In HTML Format
How To List Files and Display In HTML Format
 
How To Check and Delete a File via PowerShell
How To Check and Delete a File via PowerShellHow To Check and Delete a File via PowerShell
How To Check and Delete a File via PowerShell
 
Zimbra Troubleshooting - Mails not being Delivered or Deferred or Connection ...
Zimbra Troubleshooting - Mails not being Delivered or Deferred or Connection ...Zimbra Troubleshooting - Mails not being Delivered or Deferred or Connection ...
Zimbra Troubleshooting - Mails not being Delivered or Deferred or Connection ...
 
How To Setup SSH Keys on CentOS 7
How To Setup SSH Keys on CentOS 7How To Setup SSH Keys on CentOS 7
How To Setup SSH Keys on CentOS 7
 
How To Install and Configure Open SSH Server on Ubuntu
How To Install and Configure Open SSH Server on UbuntuHow To Install and Configure Open SSH Server on Ubuntu
How To Install and Configure Open SSH Server on Ubuntu
 
Windows PowerShell Basics - How To List PSDrive Info
Windows PowerShell Basics - How To List PSDrive InfoWindows PowerShell Basics - How To List PSDrive Info
Windows PowerShell Basics - How To List PSDrive Info
 
How To List Nginx Modules Installed / Complied on CentOS 7
How To List Nginx Modules Installed / Complied on CentOS 7How To List Nginx Modules Installed / Complied on CentOS 7
How To List Nginx Modules Installed / Complied on CentOS 7
 
Windows PowerShell Basics – How To Create powershell for loop
Windows PowerShell Basics – How To Create powershell for loopWindows PowerShell Basics – How To Create powershell for loop
Windows PowerShell Basics – How To Create powershell for loop
 
How To Construct IF and Else Conditional Statements
How To Construct IF and Else Conditional StatementsHow To Construct IF and Else Conditional Statements
How To Construct IF and Else Conditional Statements
 
How To Create PowerShell Function Mandatory Parameter and Optional Parameter
How To Create PowerShell Function Mandatory Parameter and Optional ParameterHow To Create PowerShell Function Mandatory Parameter and Optional Parameter
How To Create PowerShell Function Mandatory Parameter and Optional Parameter
 
How To Create Power Shell Function Mandatory Parameter Value
How To Create Power Shell Function Mandatory Parameter ValueHow To Create Power Shell Function Mandatory Parameter Value
How To Create Power Shell Function Mandatory Parameter Value
 
How To Create PowerShell Function
How To Create PowerShell FunctionHow To Create PowerShell Function
How To Create PowerShell Function
 
How To Find Package Installation Date on RHEL 7
How To Find Package Installation Date on RHEL 7How To Find Package Installation Date on RHEL 7
How To Find Package Installation Date on RHEL 7
 
How to Upgrade Openfire on CentOS 7
How to Upgrade Openfire on CentOS 7How to Upgrade Openfire on CentOS 7
How to Upgrade Openfire on CentOS 7
 
How To Reset root Password on CentOS 7
How To Reset root Password on CentOS 7How To Reset root Password on CentOS 7
How To Reset root Password on CentOS 7
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Navigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseNavigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern Enterprise
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Modernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaModernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using Ballerina
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cf
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Quantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation ComputingQuantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation Computing
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data Science
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 

How To Configure Nginx Load Balancer on CentOS 7

  • 1. How To Configure Load Balancer Nginx on CentOS 7 i | P a g e Table of Contents Overview.......................................................................................................................................................1 Applies To......................................................................................................................................................1 Pre-Requisites ...............................................................................................................................................1 Package Install – nginx..................................................................................................................................1 Package Install – Verify .............................................................................................................................2 Enable Service - nginx ...............................................................................................................................2 Configure – nginx ..........................................................................................................................................2 Configure Nginx – Load Balancer..............................................................................................................2 Configuration – Overview.........................................................................................................................2 Configuration – Server Directive – Node 1 and Node 2............................................................................3 Configuration – Server Directive – Load Balancer Node...........................................................................4 Upstream Section – Load Balancer...........................................................................................................5 Load Balancer Customization Table..........................................................................................................5 Testing – Load Balancer ............................................................................................................................6 Testing - Curl Utility...............................................................................................................................6 Testing – Web Browser.........................................................................................................................6
  • 2. How To Configure Load Balancer Nginx on CentOS 7 1 | P a g e Overview Nginx is an open-source, high performance HTTP & ReverseProxy Server, it can also be configured to operate as IMAP / POP3 Server. It’s well-known for high performance, stability, rich feature set, simple configuration and low resource consumption. In this guide we will configure nginx server to run as a load-balancer on a Linux based operating system. Applies To  CentOS 7, tested on CentOS Linux release 7.1.1503 (Core) Pre-Requisites 1) 3 Servers nginx installed, enabled and started; a) 1 server acts as load balancer server. b) 2 server(s) acts as webserver also acts as LB Node 1 and LB Node 2. 2) epel-release repository is installed on the server. a) If epel repository is not installed, to install run the command; yum install epel-release -y -q Package Install – nginx After installing “epel-release” repository package; install nginx package, run the command; yum install nginx -y
  • 3. How To Configure Load Balancer Nginx on CentOS 7 2 | P a g e Package Install – Verify After installation of nginx package, to confirm if the package has been successfully installed, you can run the command; yum list installed | grep nginx or rpm -qai screen | grep -E "Name| Install Date" Enable Service - nginx After installation of nginx package, next step is to configure nginx service daemon to automatically start upon server reboots. To start service automatically, run the command; systemctl enable nginx Configure – nginx By default nginx is preconfigured, if you intend to customize server parameters this can be accomplished by editing the master configuration file “/etc/nginx/nginx.conf” in “server” block section. By default port “80” is the configured for nginx service to “LISTEN”, and when the server is started, server starts automatically on IPV4 and IPV6 network interface(s). Configure Nginx – Load Balancer First step, for configuring Nginx as load balancer, each node (webserver) has to be configured to serve webpage. Once you install, configure, enable and start nginx service. Ensure that default page load’s correctly; execute the command, this command should fetch the default webpage “index.html”. curl localhost Configuration – Overview In this section we will configure load balancer, to configure it we need below servers, you can add more servers if the work loads are higher. Below table give a typical 2 node webserver and a load balancer. Server Function Hostname Web Server Node #1 vcptest01 Web Server Node #2 vcptest01 Load Balancer Node vcplbsrvr
  • 4. How To Configure Load Balancer Nginx on CentOS 7 3 | P a g e Configuration – Server Directive – Node 1 and Node 2 Next step in load balancer configuration is to configure “server” block, again if there is any specific business requirement. Default configuration is good enough, default configuration for “server” block snippet is posted below. vi /etc/nginx/nginx.conf server { listen 80 default_server; listen [::]:80 default_server; server_name _; root /usr/share/nginx/html; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }
  • 5. How To Configure Load Balancer Nginx on CentOS 7 4 | P a g e Configuration – Server Directive – Load Balancer Node Configuring Load balancer on Nginx is quite simple; create a new configuration file “load-balancer.conf” in the folder “/etc/nginx/conf.d/”, and copy and paste the below configuration snippet. vi /etc/ngnix/conf.d/load-balancer.conf upstream websrvrlb { server vcptest01; server vcptest02; } server { listen 80; location / { proxy_pass http://websrvrlb; } }
  • 6. How To Configure Load Balancer Nginx on CentOS 7 5 | P a g e Upstream Section – Load Balancer Upstream block has few directives that needs to be configured, so that load balancer can work effectively and efficiently. Directive Purpose upstream websrvrlb The servers that Nginx proxies requests to are known as upstream servers. server vcptest01; Define load balancer node, define one node per line. server vcptest02 down; Define host failed state; if any of the participating node is down for maintenance or hardware failure, set the node value “down”. listen 80; Define webserver’s Listen port. location / Define location of files to serve from. proxy_pass http://websrvrlb Define proxy server originating from specific IP Address and port, for load balancer, it is associated with upstream defined name. Load Balancer Customization Table Nginx load balancer can be customized based on the business need. This directive has to be defined inside upstream block. Load balancer method should be determined and configured based on server performance, network latency, network path, connectivity time. LB Method Directive Description Round Robin No Directive It’s default LB method; wherein requests are distributed equally across the servers it also takes into consideration the server weights. Least Connection least_conn; Request is sent to least number of current active connections, this methods also takes into consideration the server weights. IP Hash ip_hash; It can also as called sticky session server binding, it sends to request to same server, unless the requested server is not available. Hash hash; The server to which a request is sent is determined from a user- defined key which may be a text, variable, or their combination. Least Time least_time; Selects the server with the lowest average latency and the least number of active connections, this option is available for Nginx Plus version.
  • 7. How To Configure Load Balancer Nginx on CentOS 7 6 | P a g e Testing – Load Balancer Once the load balancer is configured, after restarting the service, you can test them 2 methods; 1) Web Browser 2) Command Line Interface (CLI using curl utility) Testing - Curl Utility The below screen shot is shown the request processed on bash shell prompt, when the each time the request is made, request is fetched from alternate webserver i.e., vcptest01 and vcptest02 . curl localhost Testing – Web Browser The below screenshot is shown the request processed on web browser, when the each time the request is made, request is fetched from alternate webserver i.e., vcptest01 and vcptest02. Refresh the browser