清漆请求丢失缓存尽管在

Varnish request missing cache despite being in

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

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

然后一些 PURGE 请求被发送到 Varnish,导致这个禁令列表:

ban.list 200 2108<br> 目前的禁令: 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<br> 1458150348.035639 1 丙

然后再次执行相同的 GET 请求,但出现 MISS:

* << 请求 >> 32790<br> - 开始请求 32789 rxreq - 时间戳开始:1458150371.759282 0.000000 0.000000 - 时间戳要求:1458150371.759282 0.000000 0.000000 - ReqStart 127.0.0.1 43526 - 获取请求方法 - ReqURL /organisation/xyz/proposal_0000000/comments/comment_0000001/ - ReqProtocol HTTP/1.1 - ReqHeader 主机:localhost:8088 - ReqHeader 连接:保持活动状态 - ReqHeader Pragma:无缓存 - ReqHeader 缓存控制:无缓存 - ReqHeader Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 - ReqHeader 升级不安全请求:1 - ReqHeader Referer:http://localhost:8088/organisation/xyz/proposal_0000000/comments/?elements=paths - ReqHeader 接受编码: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 接收 - VCL_return 散列 - ReqUnset 接受编码:gzip、deflate、sdch - ReqHeader 接受编码:gzip - VCL_call 哈希 - VCL_return 查找 - ExpBan 3 禁止查询 - VCL_call小姐 - VCL_return 获取 - Link bereq 32791 获取 - 时间戳获取:1458150371.779571 0.020289 0.020289 - 响应协议 HTTP/1.1 - 响应状态 200 - RespReason OK - RespHeader 服务器:gunicorn/19.2.1 - RespHeader 日期:2016 年 3 月 16 日,星期三 17:46:11 GMT - RespHeader X 缓存模式:with_proxy_cache - RespHeader X 缓存策略:HTTPCacheStrategyWeakAdapter - RespHeader 缓存控制:max-age=0,proxy-revalidate,s-maxage=31104000 - RespHeader 变化:接受编码、X 用户路径、X 用户令牌 - RespHeader 内容类型:application/json;字符集=UTF-8 - RespHeader 访问控制允许来源:* - RespHeader 访问控制允许方法:POST、GET、DELETE、PUT、OPTIONS - RespHeader Access-Control-Allow-Headers:来源、内容类型、接受、X 用户路径、X 用户令牌 - RespHeader ETag:W/“0|1|2016-03-16 13:44:05.887212+00:00|None|None” - RespHeader 内容编码:gzip - RespHeader X-清漆:32790 - RespHeader 年龄:0 - RespHeader 通过:1.1 varnish-v4 - VCL_call 交付 - VCL_return 交付 - 时间戳过程:1458150371.779598 0.020317 0.000028 - RespHeader 接受范围:字节 - RespHeader 内容长度:426 - 调试 "RES_MODE 2" - RespHeader 连接:保持活动状态 - 时间戳回复:1458150371.779641 0.020359 0.000042 - ReqAcct 598 0 598 699 426 1125 - 结尾

然后是封禁名单:

ban.list 200 147<br> 目前的禁令: 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

符合您的 URL 的规则是:

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

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

几点观察:

关于对潜伏者友好的禁止表达

阅读更多here

Lurker-friendly ban expressions are those that use only obj., but not req. variables. Since lurker-friendly ban expressions lack of req., you might need to copy some of the req. contents into the obj structure. In fact, this copy operation is a mechanism to preserve the context of client request in the cached object. For example, you may want to copy useful parts of the client context such as the requested URL from req to obj.

The following snippet shows an example on how to preserve the context of a client request in the cached object:

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

正则表达式的 Varnish 测试示例:

您可以 运行 使用: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