How to setup Varnish Cache Server on Ubuntu

By | January 29, 2014

What is Varnish Cache Server?

Varnish Cache is a web accelerator, sometimes referred to as a HTTP accelerator or a reverse HTTP proxy, that will significantly enhance your web performance and web content delivery. Varnish Cache speeds up a website by storing a copy of the page served by the web server the first time a user visits that page. The next time a user requests the same page, Varnish will serve the copy instead of requesting the page from the web server. This means that your web server needs to handle less traffic and your website’s performance and scalability go through the roof. In fact Varnish Cache is often the single most critical piece of software in a web based business. Varnish Cache is used by more than 1,7 million websites worldwide to deliver web content faster.

How does it work?

You install varnish Cache in front of any web server that uses HTTP and configure it to cache the contents. The result? Varnish will speed up the delivery of your web content significantly, depending on your architecture.

Installation on Ubuntu Server.

Varnish is distributed in the Ubuntu package repositories, but the version there might be out of date, and we generally recommend using the packages provided by Please be advised that we only provide packages for Ubuntu’s LTS releases, not all the intermediate releases. Note that the packages might still work fine on newer releases.

To use the repository, do the following:

1. curl | sudo apt-key add –
2. echo “deb saucy varnish-4.0” | sudo tee -a /etc/apt/sources.list
3. sudo apt-get update
4. sudo apt-get install varnish

If you prefer to install the older 2.1 version, replace varnish-4.0 with varnish-2.1 in the command above

To Configure your Varnish installation.

The Varnish daemon is configured by using command line:

1. vi /etc/varnish/default.vcl

Varnish comes with a default configuration ( default.vcl in /etc/varnish/ ), so you won’t have to define all the subroutines yourself. This default file is set up to work straight out of the box after you have defined a backend. Please note that default subroutines will be invoked should the custom configuration not terminate with a keyword.

Hope you find this helpful.