Manual Installation of Nginx in Cpanel Apache in proxy mode

Manual Installation of Nginx in Cpanel Apache in proxy mode

1. In order to get the cPanel server ready for nginx – you must first install an apache module called mod_rpaf

Login as root:

# cd /usr/local/src
# wget http://stderr.net/apache/rpaf/download/mod_rpaf-0.6.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

2. Doing so will install the module into the Apache module directory.

Then Go to your Web Host Manager (WHM) follow the tree here:
Main >> Service Configuration >> Apache Configuration > Include Editor > Pre Main Include and Select the apache version that is running on your cPanel server. and then add following code section there, and replace (place your ips here without the brakets) with the list of IP addresses on your Cpanel server:

LoadModule rpaf_module modules/mod_rpaf-2.0.so

RPAFenable On
# Enable reverse proxy add forward

RPAFproxy_ips 127.0.0.1  (place all your ips here without the brakets)

RPAFsethostname On
# let rpaf update vhost settings allowing to have
# the same hostnames as in the “actual” configuration for the
# forwarding apache installation

RPAFheader X-Real-IP
# Allows you to change which header we have mod_rpaf looking for
# when trying to find the ip the that is forwarding our requests

3. Once this is completed – we are ready to move Apache to another port. To move the apache to another port follow the below:

Go to your WHM  >> “tweak settings”  and change the apache port from 80 to 81 (find 0.0.0.0:80 and change it to 0.0.0.0.:81)

4. Do the following

# /usr/local/cpanel/whostmgr/bin/whostmgr2 –updatetweaksettings

5. Check your “/usr/local/apache/conf/httpd.conf” for any occurrences of port 80,

#  vi /usr/local/apache/conf/httpd.conf

Find for port 80 if you found any occurrences of port 80 then rebuild your apache configuration file by running

# /scripts/rebuildhttpdconf   and make sure your httpd.conf file is up to date

6. Then run

# /etc/init.d/httpd restart

7. Now install Nginx. You must install pcre library in order to install Nginx on your cPanel server:

# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.9.tar.gz
# tar xvzf pcre-7.9.tar.gz
# cd pcre-7.9
# ./configure
# make
# make install

Now Install Nginx

#wget http://sysoev.ru/nginx/nginx-0.7.63.tar.gz
# tar xvzf nginx-0.7.63.tar.gz
# cd nginx-0.7.63
# ./configure
# make
# make install

Download the nginx.txt file into your server:

# wget  http://experts-hosting.net/downloads/nginx.txt

then rename it to nginx.sh:

# mv nginx.txt nginx.sh

8. Change the permision and then run :

# chmod 755 nginx.sh
# sh nginx.sh

9. Now Check the Nginx configuration

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

=============================
Great install instructions, everything worked fine just some additional info if you get error like invalid event type “rtsig” when you run this commmand: # /usr/local/nginx/sbin/nginx -t

To correct this error you should do this: vi /usr/local/nginx/conf/nginx.conf
Find line 11 and change “rtsig” to “epoll” .

This error occures in case your server is using kernel 2.4.x
===============================

10. Restart Nginx

# /usr/local/nginx/sbin/nginx

11. create init script

# vi /etc/init.d/nginx

And put the below code section to the file:
========================================================================

#!/bin/sh
#
# nginx – this script starts and stops the nginx daemin
# Taken from http://www.hikaro.com
# chkconfig:   – 85 15
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse 
#               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /usr/local/nginx/conf/nginx.conf
# pidfile:     /usr/local/nginx/logs/nginx.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

nginx=”/usr/local/nginx/sbin/nginx”
prog=$(basename $nginx)

NGINX_CONF_FILE=”/usr/local/nginx/conf/nginx.conf”

lockfile=/var/lock/subsys/nginx

start()  exit 5
[ -f $NGINX_CONF_FILE ] 

stop() 
echo -n $”Stopping $prog: ”
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval


restart() 
configtest 

reload()  return $?
echo -n $”Reloading $prog: ”
killproc $nginx -HUP
RETVAL=$?
echo


force_reload() 
restart


configtest() 
$nginx -t -c $NGINX_CONF_FILE


rh_status() 
status $prog


rh_status_q() 
rh_status >/dev/null 2>&1


case “$1? in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $”Usage: $0 reload”
exit 2
esac

11. save the code and execute

# chmod +x /etc/init.d/nginx

12. make it start when the server run

# /sbin/chkconfig nginx on

13.You can run following command to check if its running:

# service nginx start
# service nginx stop
# service nginx restart
# service nginx reload
# service nginx configtest
# service nginx status

14. To Create an automatic virtualhost entry in nginx virtualhost configuration (/usr/local/nginx/conf/vhost.conf) when cPanel account get created on the server follow the below instructions:

Go to the cPanel script that is :

# vi /scripts/postwwwacct
# chmod 755 /scripts/postwwwacct

and put the same code that is used in “nginx.sh” in the step 9 and it will create an virtualhost entry to the nginx.

15.To remove virtualhost entry from nginx virtualhost configuration (/usr/local/nginx/conf/vhost.conf) when cPanel account get terminated from the server follow the below instructions:

Go to the cPanel script that is :

# vi /scripts/postwkillacct
# chmod 755 /scripts/postwkillacct

and put the same code that is used in “nginx.sh” in the step 9 and it will create an virtualhost entry to the nginx.

DONE!! Cheers!!!!

No comments yet.

Leave a Reply

Contact us

We're not around right now. But you can send us an email and we'll get back to you, asap.

Questions, issues or concerns? I'd love to help you!

Click ENTER to chat