varnish purge cache

First, we have to Specify from where the PURGE request will be allowed.
we are allowing our localhost or server itself and our developer Local Network.

# vi /etc/varnish/default.vcl
acl purgers {

sub vcl_recv {

if (req.method == “PURGE”) {
if (!client.ip ~ purgers) {
return (synth(405,”Not allowed To Purge”));
return (purge);

(saving the File)

Lets Check the Syntax of our VCL writting.
varnishd -C -f /etc/varnish/default.vcl

if Everything OK, then Restart the Varnish
# /etc/init.d/varnish restart

Now, Lets Check the PURGING.


To Test, please install ‘curl’

1. at varnish server console   Run
# varnishncsa
it will show the PURGE Command at Log.

2. Now, Run Curl for every Object of the Site
   curl -X PURGE
curl -X PURGE
curl -X PURGE
curl -X PURGE

If the content is Purged From the Varnish Cache, First time running the site will show the “Age” Header to Value ‘0’ and if we can set varnish HIT/MISS Header, we will see First visit will be ‘MISS’

3. Browse the Site from Firefox and Open the Network Browser to See the Headers.







Leave a Reply

Your email address will not be published. Required fields are marked *