Nginx as a Load Balancer

It is very basic setup of Nginx as a  load balancer. I have two Apache servers (web1.meapay.com & web2.meapay.com). Ngnix will act as a load balancer in front of these two servers

I have done it on Debian squeeze. So first we have to install nginx package

#apt-get install nginx

Edit the nginx configuration file. Before editing,  I have copied the original nginx conf file as default.orig

#cd  /etc/nginx/sites-available/

#/etc/nginx/sites-available# cp default default.orig

#vi  /etc/nginx/sites-available/default

upstream mysite {
                server web1.meapay.com;
                server web2.meapay.com;
                }

server {

        server_name  http://www.meapay.com:80;
        #listen   [::]:80 default ipv6only=on; ## listen for ipv6
        access_log  /var/log/nginx/access.log;

        location / {
                proxy_pass http://mysite;
                proxy_set_header   Host $host;
        }

}

#/etc/init.d/nginx restart

Its done.

Have FUN

Reference:

http://mickeyben.com/blog/2009/12/30/using-nginx-as-a-load-balancer/

About these ads


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

Follow

Get every new post delivered to your Inbox.