Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Varnish purge using HTTP and REGEX

I want to purge Elements of my varnish using HTTP. This http call is triggered from a backend server behind the varnish itself, so the backend server has not other access but HTTP.

I have implemented the following purging rules with the according ACL which work fine for

curl -X PURGE http://www.example.com/image/123/photo-100-150.jpg

but I want to be able to purge an URL via HTTP using Regex

curl -X PURGE http://www.example.com/image/123/*.jpg

That way I want to clear all scaled version of this image once a new has been uploaded. Is there a way?

like image 775
MatthiasLaug Avatar asked Jun 20 '12 12:06

MatthiasLaug


1 Answers

try this:

if varnish 3.0 and up.

vcl_recv {
    if (req.request == "PURGE") {
             if (!client.ip ~purge){
                     error 405 "Not allowed";
             }
     ban("req.http.host == " +req.http.host+" && req.url ~ "+req.url);
     error 200 "Ban added";

    }
like image 87
mk_ Avatar answered Oct 28 '22 16:10

mk_