We know that both Apache and Nginx are powerful and effective web-servers. Apache is the topmost webserver since it was released in 2006 and Nginx is now using top websites. The reason for using Apache and Nginx are clear, Apache’s power and Nginx’s speed.
By setting Nginx as reverse proxi, we can increase the websites speed and performance in the server. This is because, Nginx will take care of att static contents in the website such as CSS, images, SWF files, MP4 and more and Apache will manage the rest of requests (dynamic requests – php page). This is known as Nginx reverse proxy setup. Nginx stand as front end servers with a powerful backend Apache server.
nginxCP is a cpanel plugin that is used to manage nginx service in cpanel server. As we know that nginx can handle static contents better than apache, we will configure nginx to run on port 80 and will forward dynamic requests to apache on port 8081.
Installation
—————
To configure nginx as revcrse proxy, we need to install an apache module mod_rpaf.
Mod_rpaf installation:
First of all we need to login as root to do the full installation process. After login, you can proceed with following commands.
# cd /usr/local/src
# wget https://nginxda.googlecode.com/files/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
For Apache 2.4 : You need to apply a patch for mod rpaf. For that run the following commands.
# git clone git://gist.github.com/2716030.git
#patch mod_rpaf-2.0.c 2716030/mod_rpaf-2.0.c.patch
Now we are going to install nginxCP plugin. Since we need to run both Apache and nginx on the same server, we have to assign both of them in different ports. You can change apache port to 8081 from your whm tweak settings and nginx will listen to 80 as default.
For changing the Apache port, please login to WHM and go to Tweak settings.
—————————————
WHM > Server Configuration > Tweak Settings > Apache non-SSL IP/port.
—————————————
change he port to 8081 on “Apache non-SSL IP/port” option.
Now we can proceed with nginxCP installation using the following commands.
# cd /usr/local/src
# wget http://nginxcp.com/latest/nginxadmin.tar
# tar xf nginxadmin.tar
# cd publicnginx
# ./nginxinstaller install
# /usr/local/cpanel/whostmgr/bin/whostmgr ./setrhash
To server static files using nginx, you have to convert apache virtualhost to nignx virtualhost. You can download the script at http://blog.supportmonk.com/nginx.txt , rename it as nginx.sh , provide 755 permission and execute it. You have to create an empty file /usr/local/nginx/conf/vhost.conf
# touch /usr/local/nginx/conf/vhost.conf
# wget http://blog.supportmonk.com/nginx.txt
# cp nginx.txt nginx.sh
# chmod 755 nginx.sh
# ./nginx.sh
Configuration is complete. You can test nginx configuration and can start it.
# /usr/local/sbin/nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
# /etc/init.d/nginx start
While testing, there is a chance to get the following error.
——————————-
nginx: [emerg] unknown “no_cache” variable
nginx: configuration file /etc/nginx/nginx.conf test failed
——————————-
This error would be occured when you don’t have any accounts. Try to create an account using WHM and run the test command again.
That’s all..!!
Recent Comments