Nginx as Reverse proxy for Apache in Cpanel Server

The steps are given below:

cd /usr/src
wget http://sysoev.ru/nginx/nginx-0.7.63.tar.gz
wget http://stderr.net/apache/rpaf/download/mod_rpaf-0.6.tar.gz
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.9.tar.gz
tar xvzf mod_rpaf-0.6.tar.gz
cd mod_rpaf-0.6
/usr/local/apache/bin/apxs -i -c -n mod_rpaf-2.0.so mod_rpaf-2.0.c
cd /usr/src
tar xvzf pcre-7.9.tar.gz
cd pcre-7.9
./configure
make
make install
cd /usr/src
tar xvzf nginx-0.7.63.tar.gz
cd nginx-0.7.63
./configure –with-http_ssl_module –with-http_realip_module –with-http_dav_module –with-http_flv_module –with-http_gzip_static_module
make
make install

-Login to WHM and look for the following route:
Main >> Service Configuration >> Apache Setup > Include Editor > Pre Main Include

– Add the following configuration and save, LIST_OF_YOUR_IPS changing the IP you occupy in your site:

LoadModule rpaf_module modules/mod_rpaf-2.0.so
RPAFenable On
# Enable reverse proxy add forward
RPAFproxy_ips 127.0.0.1 LIST_OF_YOUR_IPS
# which ips are forwarding requests to us
RPAFsethostname On
# let rpaf update vhost settings
# allows to have the same hostnames as in the “real”
# configuration for the forwarding Apache
RPAFheader X-Real-IP
# Allows you to change which header mod_rpaf looks
# for when trying to find the ip the that is forwarding
# our requests

Change the apache port to 81 (tweak settings)
Open whm – tweak settings and find 0.0.0.0:80 and change it to 0.0.0.0.:81

– Run SSH console

/usr/local/cpanel/whostmgr/bin/whostmgr2 –updatetweaksettings
/scripts/rebuildhttpdconf
httpd restart

wget the automated nginx virtual host creator and run it

http://prajizworld.com/nginx.sh

chmod 755 nginx.sh

./nginx.sh

Remove the 3 # signs of the following lines from

/usr/local/nginx/conf/vhost.conf

#location ~* \.(gif|jpg|jpeg|png|wmv|avi|mpg|mpeg|mp4|js|css)$ {

# root /home/myweb/public_html;

#}

Check nginx configuration using

/usr/local/nginx/sbin/nginx -t

If everything is fine, its time to start nginx.

/usr/local/nginx/sbin/nginx

Configure nginx startup script

http://prajizworld.com/nginx.txt

mv nginx.txt /etc/init.d/nginx

chmod +x nginx

chkconfig –add –level 3 nginx

After doing all these, the server load was very low and pages were processing at lightning fast,

but still we experienced a slowness.

When I analyzed the traffic, I understood now network is bottleneck.

I could see many concurrent connections from same session downloading huge files.

So I thought of adding the below lines to limit traffic from same session

### Directive describes the zone, in which the session states are stored i.e. store in slimits. ###
### 1m can handle 32000 sessions with 32 bytes/session, set to 5m x 32000 session ###
limit_zone slimits $binary_remote_addr 5m;

### Control maximum number of simultaneous connections for one session i.e. ###
### restricts the amount of connections from a single ip address ###
limit_conn slimits 2;

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.