Nginx is a very fast webserver when compared with the default Apache offered by cPanel. Nginx is known for its high performance and low resource consumption. Servers hosting WordPress sites are employing Nginx as it improves the performance.
Nginx will work as a front end reverse proxy of your cPanel server along with apache, which will increase the performance. We have a plugin called ‘Nginx Admin’ which is a cPanel Nginx integration plugin.
Use the following steps to install it on a cPanel server :
1 ) Download the source files :
# cd /usr/local/src
# wget http://nginxcp.com/latest/nginxadmin.tar
# tar xf nginxadmin.tar
# cd publicnginx
2) Generate a Remote Access Key.
Generate a key by logging into WHM, going to Clusters, then Remote Key Access, and then clicking Generate New Key.
3) Run the script
# ./nginxinstaller install
This Nginx installation method integrates with WHM/cPanel and uses the Apache configuration files that WHM/cPanel uses by default.
After installation you can go to WHM, Plugins, and Nginx Admin to handle Nginx. From there you can restart Nginx, edit the configuration files, view logs, and more.
You can also restart Nginx on the command line with the Apache command:
# /etc/init.d/httpd restart
Now lets move ahead with the installation of Varnish.
Varnish is a caching technology known as web accelerator which is used as reverse HTTP proxy, which will enhance the performance of your website.
Varnish stores a copy of the page which is served by the web server the first time a user visits the website. Next time, when the user requests for the same page, varnish will serve the copy instead of serving it from the web server. Thus, your webserver is seldom bought into the lime-light if the used pages are being fetched, which improves the performance.
Before moving ahead, we will bind our webserver to the port 8081, in the file – /usr/local/apache/conf/httpd.conf,
Change the Portion – Listen 0.0.0.0:80 to Listen 0.0.0.0:8081 and restart the webservice.
Now, lets download and install the Varnish !
1) Add the repo : ( check the version of your OS ) : the URL given below is for CentOS / Redhat 5.x versions :
# wget http://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release/varnish-release-3.0-1.noarch.rpm
# rpm -Uvh varnish-release-3.0-1.noarch.rpm
2) Install the service :
# yum install varnish
3) Edit the configuration file for varnish – /etc/sysconfig/varnish
and change the value of VARNISH_LISTEN_PORT to 80
# grep VARNISH_LISTEN_PORT /etc/sysconfig/varnish
VARNISH_LISTEN_PORT=80
4) Edit Varnish config: /etc/varnish/default.vcl
. Correct the backend default Port to reflect – 8081 ( the port to which webserver was bind to )
backend default {
.host = “YOUR IP ADDRESS”;
.port = “8081”;
}
5) Start Varnish service on your server
# chkconfig varnish on
# service varnish start
You are done with installing Nginx and varnish in your cPanel server, which should improve your speed and performance.
Hi, very nice post! I got a problem when starting the varnish: VCL compilation failed. Any sugestion??
Hey Darley,
Thank you. Is it for a CentOS 5 server ?
Hi, very nice post! I got a problem when starting the varnish: VCL compilation failed. Any sugestion??
Hey Darley,
Thank you. Is it for a CentOS 5 server ?
Thanks for this tutorial, I’ve been wanting to install nginx and varnish for a while now. Nginx installed ok, varnish installed ok as well but doesn’t want to start. Any pointers? I’m on a centos 6.6 dedicated server.
The only thing I didn’t do was create a new cluster key, and that was only because there is an existing cluster key already..
Hi Cerberuz, Could you be a little more specific about the issue ? Are you getting any error messages?
Hi Arun,
I can’t really be more specific, I followed the instructions above, and when I ran
# service varnish start
It came up [failed] in the usual error red colour.
There were no issues or failures during the install of Nginx or Varnish. I can try creating a new cluster key to see if that allows varnish to start?
Pete
Hi Cerberuz,
First of all sorry for the delay in replying to your query, we were all out of office due to holidays. Hope you had a wonderful holiday season.
Coming back to the issue we would need the logs to identify what is causing this issue. You could print the logs on the terminal itself by starting the varnishd in debug mode using the following command
varnishd -d -a 0.0.0.0:80 -f /etc/varnish/default.vcl
You could check the log to identify the cause and rectify it or please feel free to post it in the reply here, so that we can have a look at it.
Thanks for this tutorial, I’ve been wanting to install nginx and varnish for a while now. Nginx installed ok, varnish installed ok as well but doesn’t want to start. Any pointers? I’m on a centos 6.6 dedicated server.
The only thing I didn’t do was create a new cluster key, and that was only because there is an existing cluster key already..
Hi Cerberuz, Could you be a little more specific about the issue ? Are you getting any error messages?
Hi Arun,
I can’t really be more specific, I followed the instructions above, and when I ran
# service varnish start
It came up [failed] in the usual error red colour.
There were no issues or failures during the install of Nginx or Varnish. I can try creating a new cluster key to see if that allows varnish to start?
Pete
Hi Cerberuz,
First of all sorry for the delay in replying to your query, we were all out of office due to holidays. Hope you had a wonderful holiday season.
Coming back to the issue we would need the logs to identify what is causing this issue. You could print the logs on the terminal itself by starting the varnishd in debug mode using the following command
varnishd -d -a 0.0.0.0:80 -f /etc/varnish/default.vcl
You could check the log to identify the cause and rectify it or please feel free to post it in the reply here, so that we can have a look at it.
NGNIX doesn’t appear to want to run, after installing Varnish, getting the following:
root@81286 [/etc/nginx]# /etc/init.d/nginx restart
Restarting nginx daemon: nginxnginx: [emerg] bind() to 173.208.146.66:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 173.208.146.66:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 173.208.146.66:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 173.208.146.66:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 173.208.146.66:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
already running.
Jason,
It seems like some service is already bind to the port 80, likely httpd. You might try killing every instances of it.
# netstat -plan | grep :80 ( it should show the PID of the process )
# kill -9 PID ( it should kill the running PID which you got from above)
# restart nginx
Thanks for the reply, that would be correct. It would be Varnish that would be running on the port 80, looking to have apache, nginx, and varnish running, but it appears following the above, nginx and varnish both want to run on 80
NGNIX doesn’t appear to want to run, after installing Varnish, getting the following:
root@81286 [/etc/nginx]# /etc/init.d/nginx restart
Restarting nginx daemon: nginxnginx: [emerg] bind() to 173.208.146.66:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 173.208.146.66:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 173.208.146.66:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 173.208.146.66:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 173.208.146.66:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
already running.
Jason,
It seems like some service is already bind to the port 80, likely httpd. You might try killing every instances of it.
# netstat -plan | grep :80 ( it should show the PID of the process )
# kill -9 PID ( it should kill the running PID which you got from above)
# restart nginx
Thanks for the reply, that would be correct. It would be Varnish that would be running on the port 80, looking to have apache, nginx, and varnish running, but it appears following the above, nginx and varnish both want to run on 80