Configure PURGE in VCL 4.0

In order to configure PURGE add this lines into your VCL_RECV:

vcl 4.0;
import std;

sub vcl_recv {

  # Allow banning  
  if (req.method == "PURGE") {
     # Same ACL check as above:
     if (!client.ip ~ purge) {
        return(synth(405, "This IP is not allowed to send PURGE requests."));
     }
     ban("req.http.host == " + req.http.host + " && req.url == " + req.url);
     # If you got this stage (and didn't error out above), purge the cached result
     return (synth(200, "Purged"));
  }

}

To test it:

$ curl -v -k -H "host: www.mydomain.com" -X PURGE http://varnish_server_ip/

Remember to add ACL into your files

3 thoughts on “Configure PURGE in VCL 4.0

  1. It is strange that ban(“req.http.host == ” + req.http.host + ” && req.url == ” + req.url); did the trick while return(purge) never did. Thank you for putting me on the right direction !

Leave a Reply