Varnish请求丢失缓存尽管存在

时间:2016-03-16 17:55:33

标签: varnish

我在Varnish缓存中有这个请求:

ReqMethod      GET
ReqURL         /organisation/xyz/proposal_0000000/comments/comment_0000001/

然后将一些PURGE请求发送到Varnish,产生此禁令列表:

ban.list 200 2108
Present bans: 1458150360.937187 16 - req.http.host == localhost:8088 && req.url ~ /organisation/xyz/proposal_0000000/team0000000$ 1458150360.929092 0 - req.http.host == localhost:8088 && req.url ~ /organisation/xyz$ 1458150360.926030 0 - req.http.host == localhost:8088 && req.url ~ /organisation/xyz/proposal_0000000/pitch0000000$ 1458150360.923491 0 - req.http.host == localhost:8088 && req.url ~ /organisation/xyz/proposal_0000000/practicalrelevance0000000$ 1458150360.921025 0 - req.http.host == localhost:8088 && req.url ~ /organisation/xyz/proposal_0000000/plan0000000$ 1458150360.918480 0 - req.http.host == localhost:8088 && req.url ~ /organisation/xyz/proposal_0000000/target0000000$ 1458150360.915931 0 - req.http.host == localhost:8088 && req.url ~ /organisation/xyz/proposal_0000000/duration0000000$ 1458150360.913486 0 - req.http.host == localhost:8088 && req.url ~ /organisation/xyz/proposal_0000000/difference0000000$ 1458150360.910710 0 - req.http.host == localhost:8088 && req.url ~ /$ 1458150360.908150 0 - req.http.host == localhost:8088 && req.url ~ /organisation$ 1458150360.906249 0 - req.http.host == localhost:8088 && req.url ~ /organisation/xyz/proposal_0000000/extrainfo0000000$ 1458150360.904289 0 - req.http.host == localhost:8088 && req.url ~ /organisation/xyz/proposal_0000000/connectioncohesion0000000$ 1458150360.901930 0 - req.http.host == localhost:8088 && req.url ~ /organisation/xyz/proposal_0000000/challenge0000000$ 1458150360.899287 0 - req.http.host == localhost:8088 && req.url ~ /organisation/xyz/proposal_0000000/goal0000000$ 1458150360.896989 0 - req.http.host == localhost:8088 && req.url ~ /organisation/xyz/proposal_0000000/partners0000000$ 1458150360.894324 0 - req.http.host == localhost:8088 && req.url ~ /organisation/xyz/proposal_0000000$ 1458150360.891701 0 C
1458150348.035639 1 C

然后再次执行相同的GET请求但是使用MISS:

* << Request >> 32790
- Begin req 32789 rxreq - Timestamp Start: 1458150371.759282 0.000000 0.000000 - Timestamp Req: 1458150371.759282 0.000000 0.000000 - ReqStart 127.0.0.1 43526 - ReqMethod GET - ReqURL /organisation/xyz/proposal_0000000/comments/comment_0000001/ - ReqProtocol HTTP/1.1 - ReqHeader Host: localhost:8088 - ReqHeader Connection: keep-alive - ReqHeader Pragma: no-cache - ReqHeader Cache-Control: no-cache - ReqHeader Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 - ReqHeader Upgrade-Insecure-Requests: 1 - ReqHeader Referer: http://localhost:8088/organisation/xyz/proposal_0000000/comments/?elements=paths - ReqHeader Accept-Encoding: gzip, deflate, sdch - ReqHeader Accept-Language: en-GB,en-US;q=0.8,en;q=0.6 - ReqHeader X-Forwarded-For: 127.0.0.1 - VCL_call RECV - VCL_return hash - ReqUnset Accept-Encoding: gzip, deflate, sdch - ReqHeader Accept-Encoding: gzip - VCL_call HASH - VCL_return lookup - ExpBan 3 banned lookup - VCL_call MISS - VCL_return fetch - Link bereq 32791 fetch - Timestamp Fetch: 1458150371.779571 0.020289 0.020289 - RespProtocol HTTP/1.1 - RespStatus 200 - RespReason OK - RespHeader Server: gunicorn/19.2.1 - RespHeader Date: Wed, 16 Mar 2016 17:46:11 GMT - RespHeader X-Caching-Mode: with_proxy_cache - RespHeader X-Caching-Strategy: HTTPCacheStrategyWeakAdapter - RespHeader Cache-Control: max-age=0, proxy-revalidate, s-maxage=31104000 - RespHeader Vary: Accept-Encoding, X-User-Path, X-User-Token - RespHeader Content-Type: application/json; charset=UTF-8 - RespHeader Access-Control-Allow-Origin: * - RespHeader Access-Control-Allow-Methods: POST,GET,DELETE,PUT,OPTIONS - RespHeader Access-Control-Allow-Headers: Origin, Content-Type, Accept, X-User-Path, X-User-Token - RespHeader ETag: W/"0|1|2016-03-16 13:44:05.887212+00:00|None|None" - RespHeader Content-Encoding: gzip - RespHeader X-Varnish: 32790 - RespHeader Age: 0 - RespHeader Via: 1.1 varnish-v4 - VCL_call DELIVER - VCL_return deliver - Timestamp Process: 1458150371.779598 0.020317 0.000028 - RespHeader Accept-Ranges: bytes - RespHeader Content-Length: 426 - Debug "RES_MODE 2" - RespHeader Connection: keep-alive - Timestamp Resp: 1458150371.779641 0.020359 0.000042 - ReqAcct 598 0 598 699 426 1125 - End

禁令名单就是:

ban.list 200 147
Present bans: 1458150360.937187 17 - req.http.host == localhost:8088 && req.url ~ /organisation/xyz/proposal_0000000/team0000000$

我知道正则表达式。 /organisation/xyz/proposal_0000000/comments/comment_0000001/如何匹配ban.list中的任何模式?这没有意义。

我正在使用Varnish 4.1.1

1 个答案:

答案 0 :(得分:1)

与您的网址匹配的规则是:

1458150360.910710     0 -  req.http.host == localhost:8088 && req.url ~ /$

regex req.url~ / $ 将匹配您的网址以及以斜杠结尾的任何其他网址;使用 req.url~ ^ / $

一些观察结果:

关于潜伏者友好的禁令表达

了解更多here

  

Lurker友好的禁令表达式仅使用obj。,而不是req。变量。由于lurker友好的禁令表达式缺少req。,您可能需要将一些req。内容复制到obj结构中。实际上,此复制操作是一种在缓存对象中保留客户端请求的上下文的机制。例如,您可能希望将客户端上下文的有用部分(例如请求的URL)从req复制到obj。

     

以下代码段显示了如何在缓存对象中保留客户端请求的上下文的示例:

sub vcl_backend_response {
   set beresp.http.x-url = bereq.url;
}

sub vcl_deliver {
   # The X-Url header is for internal use only
   unset resp.http.x-url;
}

正则表达式的清漆测试示例:

您可以使用:varnishtest test_regex.vtc

运行它

test_regex.vtc内容:

# act like a backend server
server s1 {
    rxreq
    txresp
    expect req.url == "/organisation/xyz/proposal_0000000/comments/comment_0000001/"
    expect req.http.Test == "dosent_match" 
} -start

# define & start a varnish instance
varnish v1 -vcl {
    backend default {
    .host = "${s1_addr}";
    .port = "${s1_port}";
    }

    sub vcl_recv {
    if ( req.url ~ "/$" ) {
        set req.http.Test="match";
    } else {
        set req.http.Test="dosent_match";
    }
  }

} -start

# make a client request
client c1 { 

    txreq -url "/organisation/xyz/proposal_0000000/comments/comment_0000001/"
    rxresp

} -run

varnish v1 -expect client_req == 1