Install Setup Varnish Cache in CentOS 6.5

Setup, configure and Install Varnish Cache server 3.0.5

in CentOS 6.5

You can also use this guide within your CentOS 5.x.x and 6.x.x versions.

Varnish cache server 3.0.5 is the latest stable release. Centos 6.5 is latest stable release. I installed this in my company VPS so i decide to share with needed peoples who actually just miss-understood its simple configuration.

Just follow the Steps and you will get the results.

First install latest version RPM by run the following command

If you are on RHEL and CentOS 5 or a compatible distribution, use

rpm --nosignature -i

For RHEL and CentOS 6 and compatible distributions, use

rpm --nosignature -i

and then run

yum install varnish

Once it installed successfully you need to run the followng command.

chkconfig --level 345 varnish on

Now you just need to first Finalise two thing.
1. Change the Apache port from 80 to 8080
2. Define the webserver or you can say you Main server IP within Varnish configuration file in /etc/sysconfig/varnish


nano /etc/sysconfig/varnish

You will find this part in the file which is "Alternative 3" example that varnish by default use. its best and optimise setting. Just notet the changes that i made like Port and IP in the below area. you need to made it with your own IP.

## Alternative 3, Advanced configuration## See varnishd(1) for more information.### Main configuration file. You probably want to change it:)

### Default address and port to bind to## Blank address means all IPv4 and IPv6 interfaces, otherwise specify## a host name, an IPv4 dotted quad, or an IPv6 address inbrackets.

Notice two last line with IP it was before like this


Remove the hash # and define VPS Main IP here on which Apache run. once done, hit Control+O to save then Control+X to exit from nano.

Now open second Varnish default.vcl file for defining the port for Apache connectivity.


nano /etc/varnish/default.vcl

Find this part in the file

backend default{.host ="";.port ="80";}

change the port 80 to 8080. hit Control+O to save then Control+X to exit from nano.

Now your Varnish cache web accelerator is configure on port 80 and connect with Apache server on port 8080. Now we only need to configure Apache on port 8080 on localhost IP than main VPS IP.

Open Apache default configuration file:

nano /etc/httpd/conf/httpd.conf

and change your IP with and port with 8080. it will exactly look like this below image after the change.


once done, hit Control+O to save then Control+X to exit from nano.

inCase, you use virtual host so you need to change the virtual host IP and port same like above image.

Now its time to restart Both services for effect. First Apache service and after that Varnish service. so run the following commands.

service httpd restart
service varnish restart

Now run the following command to check Varnish is work fine OR not.

curl -I

change with your website that run from the same server.

Output should be like

HTTP/1.1200 OK
session_id=fb2dede70fee22fac1b5924f0d1bc362; path=/;; 
httponlyVary:Accept-EncodingContent-Type: text/html;charset=UTF-8Date:Sat,25Jan201418:32:27 GMT
X-Varnish:1600569958Age:0Via:1.1 varnish
Connection: keep-alive

You can notice it shows "Via: 1.1 varnish" that proof varnish works abslutely fine.

Few varnish usefull commands for performance check and advance things check.

For Varnish performance check, RUN


Common commands with description


# varnishstat : Provides all the info you need to spot cache misses and errors.
# varnishhist : Provides a histogram view of cache hits/misses.
# varnishlog : Provides detailed information on requests.
# varnishtop : It reads varnishd shared memory logs and presents a most commonly occurring log entries.
# varnishadm : Command-line varnish administration used to reload vcl and purge urls.

Was this answer helpful?

 Print this Article

Also Read

Changing Server Hostname

To change your hostname, enter the following command as root: $ hostname...

Migrating Accounts to your server

Most control panels have built in control panel to control panel migration tools that you can...

Grpahical Desktop LXDE installation in VPS with Ubuntu OS for a low RAM VPS

GUI Graphical Desktop LXDE on Ubuntu VPS server with low RAM configuration....

What is guaranteed and burst memory (RAM) ?

Guaranteed memory is the amount of memory allocated to your VPS which you can use up to at any...

cPanel: Unactive License File

cPanel may spit out a "Unactive License File" error when new IP addresses or added or when your...

Powered by WHMCompleteSolution