0

I am unable to purge objects in varnish using CURL

CURL command: curl -X PURGE localhost/public/stylesheets/main.css -v the curl command is returning 200 OK response. the object is not getting purged

config file in VARNISH : default.vcl
sub vcl_miss {
  if (req.request == "PURGE") {
    purge;
    error 404 "Not in cache.";
  }
   if (req.http.user-agent ~ "spider") {
    error 503 "Not presently in cache";
    }
return (fetch);
}

sub vcl_hit {
  if (req.request == "PURGE") {
    purge;
    error 200 "Purged.";
  }
     return (deliver);
}


sub vlc.recv{
if (req.request == "PURGE") {
    if (!client.ip ~ purge) {
      error 405 "Not allowed.";
    }
    return(lookup);
  }
}

Kindly, help on this

  • can you try to add `acl purge { "localhost"; "127.0.0.1"; }` to your vcl file and test is this working ? – SAM May 27 '13 at 07:00
  • sub "vlc.recv{" has at least two typos that I can see. If that's not a copy paste error, and that's actually what your vcl looks like, you need to change it to 'sub vcl_recv {' – Johnny C Jul 23 '13 at 00:37

1 Answers1

0

enable 'PURGE' request on vcl_recv, then execute purge directly on recv, ignore if it exists or not, this is irrelevant to purge process

if (client.ip ~ purge && req.request == "PURGE" ){ purge; error 999; return(error)}
if (req.request != "GET" &&
  req.request != "HEAD" &&
  req.request != "PUT" &&
  req.request != "POST" &&
  req.request != "TRACE" &&
  req.request != "OPTIONS" &&
  req.request != "DELETE") {
    /* Non-RFC2616 or CONNECT which is weird. */
    set req.http.xpass="PASS_header";
    return (pass);
}

many times varnish don't receive the real requester IP(some non transparent proxy from your provider, like amazon load balancer), so forget client.ip ACL and do a regular expression on req.http.x-forwarded-for to match purge allowed ips... it is not secure... but may be the only simplistic alternative

sorry the poor english

BrenoZan
  • 294
  • 1
  • 7