Home > HOWTOs > NGINX – Load Balancing Web Servers.

NGINX – Load Balancing Web Servers.

Setting up NGINX for HTTP load balancing.
Nginx server is running as below.
nginx-server : nginx.server.com //nginx
Below are the 3 server which run a web application which needs to be load balanced.
Server1 : node1.application.com //web_server
Server2 : node2.application.com //web_server
Server3 : node3.application.com //web_server
Install NGINX on RHEL/Centos6
Step 1 : Create a Repo. in [vim /etc/yum.repos.d/nginx.repo]
name=nginx repo

name=nginx repo
Step 2 : Installation 
[ahmed@ngnix ~]$ sudo yum install nginx
Step 3 : Configuration: sudo vim /etc/nginx/nginx.conf
user  nginx;
worker_processes  1;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  ‘$remote_addr – $remote_user [$time_local] “$request” ‘
                      ‘$status $body_bytes_sent “$http_referer” ‘
                      ‘”$http_user_agent” “$http_x_forwarded_for”‘;

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;
    keepalive_timeout  65;
    #gzip  on;
    #include /etc/nginx/conf.d/*.conf;
    upstream myappredirect 
        server node1.application.com;
        server node2.application.com;
        server node3.application.com;
    listen 80;
        location / {
            proxy_pass http://myappredirect;
Now we are ready for testing.
[ahmed@ngnix ~]$ sudo service nginx start
Now we can go the browser and hit the IP address of nginx server.
As per the current setup (Default) it will do a Round-Robin to send request to the servers.
“All inbound request to NGINX[nginx.server.com]” -> NGINX will load_balance and distribute traffic to Servers.
Useful Links:
Categories: HOWTOs
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: