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 {
“127.0.0.1”;
“192.168.100.0”/24;
}

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.

TEST:

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 http://www.example.com/
curl -X PURGE http://www.example.com/images/image1
curl -X PURGE http://www.example.com/css/css1
curl -X PURGE http://www.example.com/js/js1

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.

Thanks.

varnish-purge

 

 

 

 

Add a Comment

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

*