清漆4,清洗 - 我以为我已经弄明白了

时间:2015-02-17 05:26:57

标签: caching varnish varnish-vcl

好吧,我会保持简单,PURGE请求(或者我认为?)几乎全部由字面处理:

acl purge {

    "localhost";

    "127.0.0.1";

}

然后

if (req.method == "PURGE") {
            if (!client.ip ~ purge) {
            return(synth(405, "This IP is not allowed to send PURGE requests."));
            }
            return (purge);
    }

我相当肯定上述两个陈述都是"正确",我挂断的是,如果我发送了

curl -X PURGE http://domain.com/

curl -X PURGE http://domain.com/.*

和Varnish发回200 Purged well ...缓存被清除了?即使它只是主页而不是整个缓存(发誓它都是使用上面的。*方法)并且上面的代码片段是正确的,有任何特殊原因http://domain.com(如同实际主页)没有被清除?

varnishncsa显示:

MYIP - - [16/Feb/2015:23:23:10 -0600] "PURGE http://domain.com/ HTTP/1.1" 200 241 "-" "curl/7.29.0"

我知道我得失去一些愚蠢的东西,但我无法理解它?

1 个答案:

答案 0 :(得分:1)

official documentation基本上说你做了什么,但请记住PURGE!= BAN,你可以在BAN中使用正则表达式,但不能在PURGE中使用。使用PURGE,您可以删除一个特定网址的所有Vary定义副本。

在我使用4.0.2的测试中,它按照建议工作,我将主页缓存,我执行curl -X PURGE http://localhost:8080/并在varnishlog中看到(除其他外):

*   << Request  >> 65542     
-   Begin          req 65541 rxreq
-   Timestamp      Start: 1424188792.108573 0.000000 0.000000
-   Timestamp      Req: 1424188792.108573 0.000000 0.000000
-   ReqStart       ::1 60496
-   ReqMethod      PURGE
-   ReqURL         /

-   VCL_acl        MATCH purge "localhost"
-   VCL_return     purge
-   VCL_call       HASH
-   VCL_return     lookup
-   VCL_call       PURGE

重装我看到一个MISS&amp;后端请求(因为它不在缓存中):

*   << BeReq    >> 65548     
-   Begin          bereq 65547 fetch
-   Timestamp      Start: 1424188815.112540 0.000000 0.000000
-   BereqMethod    GET
-   BereqURL       /
-   BereqProtocol  HTTP/1.1

-   VCL_call       BACKEND_RESPONSE
-   TTL            VCL 120 21600 0 1424188815
-   VCL_return     deliver

*   << Request  >> 65547     
-   Begin          req 65546 rxreq

-   ReqMethod      GET
-   ReqURL         /

-   VCL_return     hash
-   VCL_call       HASH
-   VCL_return     lookup
-   Debug          "XXXX MISS"
-   VCL_call       MISS
-   VCL_return     fetch
-   Link           bereq 65548 fetch

BTW在purge acl的ips列表中添加“:: 1”,以防您使用ipv6。它会返回405,但谁知道。