Wednesday, 9 September 2015

How to install Nginx as reverse proxy on cPanel server?

The web-hosting control panel’s default web-server is Apache. cPanel/WHM doesn’t have native support on Nginx. But, we can install and configure it may ways. That will improve the server performance.

Nginx as reverse proxy for Apache is good for its speed and ability to handle large number of requests simultaneously with optimal use of resources. The main concept behind this is Nginx will take care of all the static files of your websites (css, images, swf files, mp4, javascript files, and more), and pass the rest of the requests (dynamic requests — php files –) to Apache web server. This is called Nginx reverse proxy, where Nginx stands as front end server,with a Backend server.

One of the good things of this configuration, is that you don’t need to change a single thing in your websites, as your code and .htaccess files are 100% compatible. This is one of the easiest and fastest way to install Nginx on cPanel server.

This are some of the features of this wonderful script:

*Compatible with WHM: allows you to configure and analyze nginx logs with a GUI.

*Gzip compression: it is compatible with Gzip compression, which will allow you to get faster speeds.

*Integrated with the cPanel Service Monitor configuration

You can choose which domains will use Apache and which will use Nginx as reverse proxy.

Installing Nginx on cPanel.

1)Login to your server via SSH (as root).

ssh root@1.1.1.1 -p 1122

2)Once logged in successfully, you'll need to change into the /usr/local/src directory.

cd /usr/local/src

3)Now, simply download the plugin using wget.

wget http://nginxcp.com/latest/nginxadmin.tar

4)Now that it's been downloaded, you need to extract the compressed plugin.

tar xf nginxadmin.tar

5)Change into the publicnginx directory.

cd publicnginx

6)Run the included executable installer program with the 'install' flag.

./nginxinstaller install

If you've never setup a Remote Access Key, you'll see the following error: access key doesn't exist To fix this, you'll need to login to WHM, visit the "Clusters" section, select " Remote Access Key" then select "Generate New Key".

Move to WHM >  Cluster/Remote Access > Setup Remote Access Key and click at “Generate New Key button”

If all goes smoothly, the end result should print something similar to the following:

 ****************************************************
 *               Installation Complete              *
 *run /etc/init.d/httpd restart to start Nginx Admin*
 ****************************************************

7)Restart the webserver daemon.

/etc/init.d/httpd restart

Which should result with output similar to this:

 ****************************************************
Restarting nginx daemon: nginxRemaining processes: 10207
 ****************************************************

NginxCP (nginx as a reverse proxy) is now installed and can be viewed/accessed/configured via WHM. To access the Control Panel for nginx, visit your WHM Panel » Plugins » nginx Admin.

P.S. Make sure that the Nginx is running on port 80 and Apache on different port (like 8080). Also open the new port the server firewall.

That’s it!

No comments:

Post a Comment