Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

I want to cache for 10 minutes and for 1 minute but whenever is visited, I want to to clean the cache for Any help?

share|improve this question

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

curl -X PURGE

But this presupposes you've got scripting at

I imagine it would be possible to call the purge in a VCL handler for

sub vcl_recv {
   if (req.url ~ "^") {
      purge("req.url ==");

(not tested)

share|improve this answer

Part 1:

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

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

For your domain root, this will work*

varnishadm -S /etc/varnish/secret -T localhost:6082 "ban == && 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 is visited.

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

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.