I have zero experience with varnish. I want to setup varnish to do something very basic: I have two pages


I want to cache http://mysite.com/additem for 10 minutes and http://mysite.com/ for 1 minute but whenever http://mysite.com/additem is visited, I want to to clean the cache for http://mysite.com/. Any help?


IIRC there's a cli program (purge) which you could call from http://mysite.com/additem, or use curl to send a purge instruction (as a HTTP verb) e.g.

curl -X PURGE http://mysite.com/

But this presupposes you've got scripting at http://mysite.com/additem

I imagine it would be possible to call the purge in a VCL handler for http://mysite.com/additem

sub vcl_recv {
   if (req.url ~ "^http://mysite.com/additem") {
      purge("req.url == http://mysite.com/");

(not tested)


Part 1:

This command will clean (purge) a sub-folder (for example)

varnishadm -S /etc/varnish/secret -T localhost:6082 "ban req.http.host == mysite.com && req.url ~ ^/fold/.*$"

For your domain root, this will work*

varnishadm -S /etc/varnish/secret -T localhost:6082 "ban req.http.host == mysite.com && req.url ~ ^/.*$"

*Note: Needs to be tested to see if the above purges sub-folders (recursive)

Part 2: Are you in charge of the server and not using it for (m)any other users? Do you allow system commands in PHP? If yes, it should be easy to run the command whenever http://mysite.com/additem is visited.

The above commands work from CLI, not tested yet the other way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.