Installing Varnish


In this video we discuss reverse proxy caching and install the popular cache application Varnish.

As of Feb 2012 the download URL used for adding the RPM for Varnish has changed: is now

One of our members contributed the following notes for this video. Thanks, Mike!

Nice video. I took a few notes like one of the other commenters in the mysql config video. I have also found a few helpful links. I thought I would share here for everyone. Please comment if anything needs to be corrected.

*From Nate at Lullabot:

"Varnish usually has three locations of configuration. The boot script, the system-wide configuration, and the VCL file that does most of the work.

The first script that starts up Varnish is usually located with the rest of your system startup scripts at /etc/init.d/varnish. This file rarely needs adjustments, but it can be interesting to read or help you locate further configuration (since the startup script is responsible for calling the next file).

The second file is usually located at /etc/sysconfig/varnish (on CentOS and RedHat machines) or /etc/default/varnish (on Ubuntu). This file defines global configuration for Varnish such as which port it should run on and where it should store its cache.

The VCL file is the main location for configuring Varnish and it's where we'll be doing the majority of our changes."

VCL File Location

--please see the full article for more information. It reiterates the information in this video as well as delivers details about more complex logic.
Configuring Varnish for High-Availability with Multiple Web Servers

Varnish default VCL file from Lullabot for Varnish 2.X

Notes of syntax changes for Varnish 3 from 2

Basic Settings for Listen:
-Varnish will listen at 80. Apache has to listen to Varnish. In the example the port was changed from 80 to 8080 at httpd.cnf

And then Varnish has to be told in the default.vcl file to pass info to Apache at 8080.

>service varnish restart
>service httpd restart (apache restart)
>apache2ctl graceful (ubuntu apache restart)

>varnishlog (this shows an real time activity as your site is browsed.)

Use Firefox/Firebug/Net
to see watch how the page is loaded.
X-Varnish 1810994694 1810994085
X-Varnish-Cache HIT

On a refresh, if you do not see two time stamps at X-Varnish you may want to check your cookie settings in the vcl file. Modules and or some sort of embed can add extra cookies. Also in the status column of Net it should read 200. If you see 304 not modified you are caching locally and therefore there will be varnish cache resulting in a Miss. (please correct this if I am wrong)

The hardest thing in I encountered was setting up the default.vcl file. It was very easy to miss something small if editing by hand.

More helpful info:


Average review

No votes yet