A quick reminder on what varnish is.
Varnish is a web cache that runs on Linux, it listens on port 80 (the usual HTTP port) and connects to a web server such as Apache running on an alternate port on the server, such as 8080. Varnish stores/caches the copies of your pages and when requested by a visitor it serves those pre-built pages without having to process them over and over again.
Since Varnish listens on Port 80 (HTTP), we will first need to change the port for Apache running on our server. We will be changing the Apache port to 8080. To do this, login to your WHM as root, click on Tweak Settings from the sidebar, head over to the system tab and change the Apache Non-SSL port to 8080.
Now, we can proceed with the installation of Varnish. You need to be logged in as root via SSH. Type:
Install Varnish Repository
Install Varnish
Once the installation completes, we will configure Varnish to listen on port 80.
Edit the file /etc/sysconfig/varnish using your preferred editor.
VARNISH_LISTEN_PORT=80
Varnish is not a web server, it is merely a proxy sitting in front of a web server such as Apache, this implies that you would still need to run Apache on an alternate port on your server (such as 8080) and varnish in turn connects to Apache on the backend and listens on port 80 in the front end.
We now need to configure Varnish to connect to Apache on port 8080. Type in the following:
Paste the following code.
Make sure you replace the <your server’s IP address> with the IP address of your server. Finally enter:
service varnish start
You can monitor the performance of your Varnish cache using the command line tool :
That is it, you now have varnish running on your server.
Varnish is a web cache that runs on Linux, it listens on port 80 (the usual HTTP port) and connects to a web server such as Apache running on an alternate port on the server, such as 8080. Varnish stores/caches the copies of your pages and when requested by a visitor it serves those pre-built pages without having to process them over and over again.
Since Varnish listens on Port 80 (HTTP), we will first need to change the port for Apache running on our server. We will be changing the Apache port to 8080. To do this, login to your WHM as root, click on Tweak Settings from the sidebar, head over to the system tab and change the Apache Non-SSL port to 8080.
Now, we can proceed with the installation of Varnish. You need to be logged in as root via SSH. Type:
Install Varnish Repository
Code:
rpm -Uvh http://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release-3.0-1.noarch.rpm
Install Varnish
Code:
yum install varnish
Once the installation completes, we will configure Varnish to listen on port 80.
Edit the file /etc/sysconfig/varnish using your preferred editor.
Code:
nano /etc/sysconfig/varnish
VARNISH_LISTEN_PORT=80
Varnish is not a web server, it is merely a proxy sitting in front of a web server such as Apache, this implies that you would still need to run Apache on an alternate port on your server (such as 8080) and varnish in turn connects to Apache on the backend and listens on port 80 in the front end.
We now need to configure Varnish to connect to Apache on port 8080. Type in the following:
Code:
cd /etc/varnish/
Code:
mv default.vcl default_bak.vcl
Code:
touch default.vcl #creating a new default config file
Code:
nano default.vcl
Paste the following code.
Code:
backend default {
.host = "<your server's IP address>";
.port = "8080";
}
sub vcl_recv {
if (req.url ~ "\.(png|gif|jpg|swf|css|js)$") {
return(lookup);
}
}
# strip the cookie before the image is inserted into cache.
sub vcl_fetch {
if (req.url ~ "\.(png|gif|jpg|swf|css|js)$") {
unset beresp.http.set-cookie;
}
}
Make sure you replace the <your server’s IP address> with the IP address of your server. Finally enter:
Code:
chkconfig varnish on
service varnish start
You can monitor the performance of your Varnish cache using the command line tool :
Code:
varnishstat
That is it, you now have varnish running on your server.