How To install Varnish with Apache 2 on Ubuntu

Varnish Cache is a web application accelerator also known as a caching HTTP reverse proxy. You install it in front of any server that speaks HTTP and configure it to cache the contents.

Why Varnish :
To reduce server load.
To make a website load faster, because cache stored in RAM.
To gain more visitors, because every webmaster love it.

To install Apache on your server use below commands
#sudo apt-get install apache2

Step 1 : Install Varnish
#sudo curl | sudo apt-key add –

In next step add repository to list of apt source, to do this you should open the file /etc/apt/source.list and add following line

vim /etc/apt/sources.list
deb lucid varnish-3.0

Now Install varnish
#sudo apt-get update
#sudo apt-get install varnish

Step 2 : Varnish Configuration

Once you have Apache and Varnish install, you should set some basic configuration parameters

vim /etc/default/varnish

Uncomment all of the lines under “DAEMON_OPTS”—under Alternative 2, and make the configuration match the following code:

DAEMON_OPTS=”-a :80 \
-T localhost:6082 \
-f /etc/varnish/default.vcl \
-S /etc/varnish/secret \
-s malloc,256m”

Now save the file.

Now you have to edit the file /etc/varnish/default.vcl. This file tells varnish where to look for the webserver content.

#vim /etc/varnish/default.vcl
configuration should look like this

backend default {
.host = “”;
.port = “8080”;

The config above says that Apache as the backend server is available on localhost at port 8080 and Varnish will run in front of it listening on port 80 that previously used by Apache.

Step 3 : Apache Configuration
#vim /etc/apache2/ports.conf

Change the port for both NameVirtualHost and Listen to 8080. The configuration should look like this:


Also make the changes in default virtual host file as its still listing on port 80 change and make it to 8080.

#sudo vim /etc/apache2/sites-available/default

updated line should look like this:


now restart both services to make the changes effective.
#sudo service apache2 restart
#sudo service varnish restart

you can see the details of varnish’s workings with this command:

Leave a Reply