Wednesday, 11 May 2011

Nginx with Cpanel Apache in proxy mode

This manual is useful for those wishing to install Nginx web server in Cpanel to manage static content using less cpu and ram, so we just loaded PHP to Apache.
tested on ( Cpanel 11.28, CentOS 5 x86_64, PHP 5.2.16 and Apache 2.2 )

cd /usr/src
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.c
cd /usr/src
tar xvzf pcre-7.9.tar.gz
cd pcre-7.9
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 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/
RPAFenable On
# Enable reverse proxy add forward
# 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 and change it to
Run SSH console
# /usr/local/cpanel/whostmgr/bin/whostmgr2 –updatetweaksettings
# /scripts/rebuildhttpdconf
# service httpd restart
wget the automated nginx virtual host creator
- chmod the file and run it
# chmod 755
# ./
Here you will get error then follows this steps
Find & replace the line /usr/local/nginx/conf/nginx.conf < to /usr/local/nginx/conf/nginx.conf < Again run the script
# ./
-Now check the configuration
# /usr/local/nginx/sbin/nginx -t
Start nginx
# /usr/local/nginx/sbin/nginx
Until now only the managing nginx connections, but is not serving static content. For the latter you must edit the following file:
-Remove the 3 # signs of the following lines, so the final configuration will looks like
location ~* \.(gif|jpg|jpeg|png|wmv|avi|mpg|mpeg|mp4|js|css)$ {
root /home/myweb/public_html;
–Restart nginx in SSH
/usr/local/nginx/sbin/nginx -s reload

No comments:

Post a Comment