Step 1:
Install nginx. If you have not already done so, install the epel repository:
wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm rpm -ivh epel-release-6-8.noarch.rpm yum install nginx
The configuration file is stored in /etc/haproxy/haproxy.cfg. You may want to back this file up as it will be modified in the next step. You can also set up the service to start at boot:
chkconfig nginx on
Step 2:
Set up the server configuration. The configuration file that will be modified is /etc/nginx/conf.d/default.conf. You may want to back up this file before proceeding. Some of the changes that will be made to this file are shown below.
server{ listen 1.1.1.1:80; server_name example.com; location / { proxy_pass http://webservice; } } upstream webservice{ server 10.0.0.2:80; server 10.0.0.3:80; }
Note that the backend servers will be apache servers.
Step 3:
Set up the backend servers defined in haproxy.cfg. In this example, just the apache test page is being used. Apache can be installed with a simple
yum install httpd service httpd on
Step 4:
Verify functionality.Checking the access logs on the nginx machine at /var/logs/nginx/access.log show the client making the connection. Checking the apache logs at /var/logs/httpd/access.log on the servers behind the proxy show the requests being load balanced across both machines. Taking down one of the apache servers results in the site staying up, but requests only being passed to the active server.