I wanted to play with a simple load balancer with powerful implications. A load balancer using nginx as the front end and two apache servers on the backend. All using CentOS 6 minimal installations.
server1 - apache - 192.168.1.89
yum -y install httpd echo server1 /var/www/html/index.html lokkit -s http -s https chkconfig httpd on && service httpd restart
server2 - apache -192.168.1.90
yum -y install httpd echo server2 /var/www/html/index.html lokkit -s http -s https chkconfig httpd on && service httpd restart
load balancer - nginx - 192.168.1.88
Add the nginx repository
vi /etc/yum.repos.d/nginx.repo
Copy and past the following into the nginx.repo file and save it.
[nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=0 enabled=1
Install nginx
yum install -y nginx service nginx start lokkit -s http -s https
Modifiy the default.conf file.
vi /etc/nginx/conf.d/default.conf
Add to the top the upstream section and under location below the two proxy* lines.
upstream web_backend { # ip_hash; server 192.168.1.89; server 192.168.1.90; } server { listen 80; server_name localhost; location / { root /usr/share/nginx/html; index index.html index.htm; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://web_backend; }
Restart nginx.
service nginx restart
Using your favorite web-browser, type in http://192.168.1.88 and refresh the page a few times to see the text change from server1 to server2.
Source(s)
https://www.nginx.com/resources/admin-guide/reverse-proxy/
https://www.nginx.com/resources/wiki/start/topics/tutorials/install/
http://think-devops.blogspot.com/2013/03/nginx-crumbs.html