After struggling to find a good article about how to setup Magento 1, Varnish and Turpentine. I’ve decided to write my own.
This example is for applications running on UBUNTU. It doesn’t change much if you’re using other distros, but I thought you should keep it in mind.

Screen Shot 2016-04-20 at 9.58.54 PM

Install Varnish

As root, run the commands below:
$ apt-get install apt-transport-https
$ curl | apt-key add -
$ echo "deb trusty varnish-4.0" >> /etc/apt/sources.list.d/varnish-cache.list
$ apt-get update
$ apt-get install varnish

Setup Varnish

Now, with an editor open the file  /etc/default/varnish

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

(For Varnish version 3.x)
DAEMON_OPTS="-p esi_syntax=0x2 \
 -p cli_buffer=16384 \
 -a :80 \
 -T localhost:6082 \
 -f /etc/varnish/default.vcl \
 -S /etc/varnish/secret \
 -s malloc,256m"
(For Varnish version 4.x)
DAEMON_OPTS=" -a :80 \
 -T localhost:6082 \
 -f /etc/varnish/default.vcl \
 -S /etc/varnish/secret \
 -p feature=+esi_ignore_other_elements \
 -p cli_buffer=16384 \
 -p vcc_allow_inline_c=on \
 -s malloc,256m"
The “/etc/varnish/default.vcl” file tells Varnish where to find the WebServer content. Within this file, we will tell varnish to look for the content on port 8080 once we will change the port of our Webserver later.

The configuration should like below. If your server is in another IP/Server, change the value in host accordingly.

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


 At the time I’m writing this article Turpentine is on its version 0.6.8 and it’s compatible with the Varnish 4.0 we’ve installed above. You can download the extension for Magento here. Once you’ve installed it go to System > Configuration > Varnish Options. You should be able to see something like below:

Add your secret key into the field Varnish Authentication Key with a “\n” at the end. The secret key is located at /etc/varnish

/secret. Back on the terminal, run “ps aux |grep varnishd” to see something like

Screen Shot 2016-04-14 at 6.10.50 PM
Get sure the field Server List matches the -T parameter in the config. On this case, localhost:6082.
Save the configs.

Go to System > Cache Management and click on Save Varnish Config.


Change your application’s port to listen to 8080 instead the current 80. In Nginx, for instance, it would look like :
server {
        listen   8080;


Change the port number for both the NameVirtualHost and the Listen line to port 8080, and the virtual host should only be accessible from the localhost. The configuration should look like this:

The Virtual Host should also be set to port 8080, and updated line looks like this:


Save it. That’s all you need to do for now.


When you pressed Save Varnish Config, it generated an default.vcl file in your var directory. Now we need to make it available for Varnish to read our website configurations.  We will do it by replacing the default file. But first, let’s make a backup just in case:
$ sudo mv /etc/varnish/default.vcl /etc/varnish/default.vcl_bkp
Now create a symlink of the file generated by Turpentine:
$ sudo ln -s /PATH_TO_YOUR_MAGENTO_DIR/var/default.vcl /etc/varnish/
Now, let’s get the settings applied for the the right ports by restarting the services
$ sudo service nginx stop
$ sudo service varnish restart
$ sudo service nginx start

To test if everything is working fine run “$ sudo netstat -tulpn” and you should see port 80 assigned to varnishd and 8080 for Nginx/Apache:

Screen Shot 2016-04-14 at 5.25.35 PM

Look at the Varnish log

Make sure Varnish is running then enter the following command on the Varnish server:


In a web browser, go to any Magento page.

A long list of response headers display in your command prompt window. Look for headers like the following:

-   BereqHeader    X-Varnish: 3
-   VCL_call       BACKEND_FETCH
-   VCL_return     fetch
-   BackendOpen    17 default(,,8080) 60914
-   Backend        17 default default(,,8080)
-   Timestamp      Bereq: 1440449534.261791 0.000618 0.000618
-   ReqHeader      Host:
-   ReqHeader      Connection: keep-alive
-   ReqHeader      Content-Length: 86
-   ReqHeader      Cache-Control: max-age=0
-   ReqHeader      Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
-   ReqHeader      Origin:

If headers like these do not display, stop Varnish, check your default.vcl, and try again.

Look at HTML response headers

There are several ways to look at response headers, including using a browser plug-in like Live HTTP Headers (Firefox, Chrome), or a browser inspector.

The following example uses curl. You can enter this command from any machine that can access the Magento server using HTTP.

curl -I -v --location-trusted '<your Magento base URL>'

For example,

curl -I -v --location-trusted ''

Look for headers like the following:

Content-Type: text/html; charset=iso-8859-1
X-Varnish: 15
Age: 0
Via: 1.1 varnish-v4
X-Magento-Cache-Debug: HIT

Happy Coding!

References MedinaMagentoAfter struggling to find a good article about how to setup Magento 1, Varnish and Turpentine. I've decided to write my own. This example is for applications running on UBUNTU. It doesn't change much if you're using other distros, but I thought you should keep it in mind. Install Varnish As root,...A Magento Craftsman in Melbourne