Varnish Cache is a powerful open source HTTP accelerator that can be installed infront of any Webserver. Varnish Cache can improve overall performance of your web server by caching contents. The Varnish cache stores the copy of user request’s and serves the same page when the user revisits the webpage.
Installing Varnish Cache on Centos.
==========================
The Varnish Cache can be installed from Official Varnish repository.
Run the below command to enable Varnish Repo in Centos6
wget http://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release-3.0-1.noarch.rpm
rpm –nosignature -i varnish-release-3.0-1.noarch.rpm
Now you can install varnish using yum command
yum install varnish
Configurations
In this tutorial I am using nginx as Webserver.
The first step is changing nginx default port.
Open the configuration file
vim /etc/nginx/conf.d/default.conf
Replace the port 80 to 8080.
# The default serverserver {
listen 8080;
server_name ntn-blog.com;
Add a firewall rule to allow this port in iptables
iptables -I INPUT -p tcp –dport 8080 –syn -j ACCEPT
Now we are going to configure Varnish to run on port 8O.
The main configuration file for Varnish is /etc/sysconfig/varnish
Open the configuration file
vim /etc/sysconfig/varnish
Change the below parameters
VARNISH_LISTEN_PORT=80
VARNISH_STORAGE_SIZE=512M
And another configuration file is /etc/sysconfig/varnish which is used to communicate with nginx webserver running on port 8080.
Open up the configuration file
vim /etc/sysconfig/varnish
Modify the parameters as given below
backend default {.host = “127.0.0.1″;
.port = “8080″;
}
Finally restart the services
service nginx restart
service varnish restart
Test the installation by running below command in server
curl -I ntn-blog.com
You will get output like this.HTTP/1.1 200 OK
Server: nginx/1.0.15Content-Type: text/html; charset=UTF-8X-Powered-By: PHP/5.3.3X-Pingback: http://ntn-blog.com/xmlrpc.php
Content-Length: 7993
Date: Tue, 19 Nov 2013 14:15:16 GMT
X-Varnish: 274529218
Age: 0
Via: 1.1 varnish
Connection: keep-alive
Thats all …… 🙂