Question

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

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top