无法使用VARNISH上的CURL清除

时间:2013-05-23 17:02:11

标签: curl varnish varnish-vcl

我无法使用CURL

清除varnish中的对象

CURL命令:     curl -X PURGE localhost / public / stylesheets / main.css -v curl命令返回200 OK响应。对象没有被清除

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);
  }
}

请帮助,

1 个答案:

答案 0 :(得分:0)

在vcl_recv上启用'PURGE'请求,然后直接在recv上执行purge,忽略它是否存在,这与清除过程无关

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);
}
多次清漆没有收到真正的请求者IP(来自您的提供者的某些非透明代理,如amazon负载均衡器),所以忘记client.ip ACL并在req.http.x-forwarded-for上执行正则表达式匹配purge允许的ips ...它不安全...但可能是唯一的简单替代

对不起那个可怜的英语