Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

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.

share|improve this answer

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)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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