Setup Varnish Cache

From Brian Nelson Ramblings
Revision as of 06:29, 19 January 2014 by Brian (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Varnish Cache Setup

Setting up Varnish Cache with default.vcl

What is Varnish Cache?

Varnish is a web application accelerator. You install it in front of your web application and it will speed it up significantly.

Once finished the reader should have a basic Varnish 3.0 cache up and running with the default configuration.

Install Varnish YUM Repository

rpm --nosignature -i

Install Varnish with Yum

yum install varnish -y

Make Varnish start on Boot

chkconfig varnish on

Now the basic Varnish install is complete, now lets start it

/etc/init.d/varnish start

Configure Varnish to use Port 80

The default installation of Varnish will start off listening to port 6081

You will want to adjust this to listen on port 80 so that it will cache incoming web requests.

vim /etc/sysconfig/varnish

Adjust the following value to port 80


Configure http/Apache to port 81

Now if you have httpd already started will you will want to stop and make httpd listen on another port, example port 81

sed -i 's/80/81/g' /etc/httpd/conf/httpd.conf

Now restart apache so it will start listen on port 81

/etc/init.d/httpd restart && /etc/init.d/varnish restart

Now apache will be listing on port 81 and varnish will listen on port 80

Configure Varnish to Use Apache port 81

Now you will want to edit you default.vcl file, to tell it use

vim /etc/varnish/default.vcl

Change backend to use port 81, by default its set to port 80.

 backend default {
  .host = "";
  .port = "81";

Now one last varnish restart, and you are up and running with the default varnish installation

/etc/init.d/varnish restart

Lets Verify Everything is Correct

Now we check and make sure httpd is listen on port 81 and varnish is listening on port 80

netstat -nptl | grep -E '80|81'

Varnish Setup

Additional Articles