Varnish 通过调用“hit_for_pass”拒绝缓存

Varnish 通过调用“hit_for_pass”拒绝缓存
   13 StatSess     c 127.0.0.2 48714 0 1 1 0 1 1 687 2573
   24 BackendXID   b 1374630903
   24 TxRequest    b GET
   24 TxURL        b /do_ajax.php?action=get-dom
   24 TxProtocol   b HTTP/1.0
   24 TxHeader     b X-Forwarded-Proto: https
   24 TxHeader     b X-Forwarded-Port: 443
   24 TxHeader     b Host: www.officestocks.com
   24 TxHeader     b Accept-Language: en-US,en;q=0.9
   24 TxHeader     b Accept: text/plain, */*; q=0.01
   24 TxHeader     b User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 15_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.3 Mobile/15E148 Safari/604.1
   24 TxHeader     b Referer: https://www.officestocks.com/
   24 TxHeader     b X-Requested-With: XMLHttpRequest
   24 TxHeader     b X-Remote-IP: 184.89.213.63
   24 TxHeader     b X-Forwarded-For: 184.89.213.63
   24 TxHeader     b Accept-Encoding: gzip
   24 TxHeader     b X-Varnish: 1374630903
   24 RxProtocol   b HTTP/1.1
   24 RxStatus     b 200
   24 RxResponse   b OK
   24 RxHeader     b Date: Fri, 04 Mar 2022 20:20:57 GMT
   24 RxHeader     b Server: Apache/2.2.15 (CentOS)
   24 RxHeader     b X-Robots-Tag: noindex
   24 RxHeader     b X-Content-Type-Options: nosniff
   24 RxHeader     b Expires: Wed, 11 Jan 1984 05:00:00 GMT
   24 RxHeader     b Cache-Control: no-cache, must-revalidate, max-age=0
   24 RxHeader     b X-Frame-Options: SAMEORIGIN
   24 RxHeader     b Referrer-Policy: strict-origin-when-cross-origin
   24 RxHeader     b Vary: Accept-Encoding,User-Agent
   24 RxHeader     b Content-Encoding: gzip
   24 RxHeader     b Connection: close
   24 RxHeader     b Content-Type: text/html; charset=UTF-8
   24 Fetch_Body   b 5(eof) cls 0 mklen 1
   24 Length       b 26
   24 BackendClose b default
   12 SessionOpen  c 127.0.0.2 48702 127.0.0.2:80
   12 ReqStart     c 127.0.0.2 48702 1374630903
   12 RxRequest    c GET
   12 RxURL        c /do_ajax.php?action=get-dom
   12 RxProtocol   c HTTP/1.0
   12 RxHeader     c X-Real-IP: 184.89.213.63
   12 RxHeader     c X-Forwarded-For: 184.89.213.63
   12 RxHeader     c X-Forwarded-Proto: https
   12 RxHeader     c X-Forwarded-Port: 443
   12 RxHeader     c Host: www.officestocks.com
   12 RxHeader     c Connection: close
   12 RxHeader     c Accept-Language: en-US,en;q=0.9
   12 RxHeader     c Accept-Encoding: gzip, deflate, br
   12 RxHeader     c Accept: text/plain, */*; q=0.01
   12 RxHeader     c User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 15_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.3 Mobile/15E148 Safari/604.1
   12 RxHeader     c Referer: https://www.officestocks.com/
   12 RxHeader     c Cache-Control: max-age=1000
   12 RxHeader     c X-Requested-With: XMLHttpRequest
   12 VCL_call     c recv
   12 VCL_acl      c MATCH proxyIps 127.0.0.2
   12 VCL_return   c lookup
   12 VCL_call     c hash
   12 Hash         c /do_ajax.php?action=get-dom
   12 Hash         c www.officestocks.com
   12 Hash         c 443
   12 Hash         c 
   12 VCL_return   c hash
   12 HitPass      c 1374630098
   12 VCL_call     c pass pass
   12 Backend      c 24 default default
   12 TTL          c 1374630903 RFC 0 -1 -1 1646425258 0 1646425257 442645200 0
   12 VCL_call     c fetch
   12 TTL          c 1374630903 VCL -0 120 -1 1646425258 -1
   12 TTL          c 1374630903 VCL 121 120 -1 1646425258 -1
   12 VCL_return   c hit_for_pass
   12 ObjProtocol  c HTTP/1.1
   12 ObjResponse  c OK
   12 ObjHeader    c Date: Fri, 04 Mar 2022 20:20:57 GMT
   12 ObjHeader    c Server: Apache/2.2.15 (CentOS)
   12 ObjHeader    c X-Robots-Tag: noindex
   12 ObjHeader    c X-Content-Type-Options: nosniff
   12 ObjHeader    c Expires: Wed, 11 Jan 1984 05:00:00 GMT
   12 ObjHeader    c Cache-Control: no-cache, must-revalidate, max-age=0
   12 ObjHeader    c X-Frame-Options: SAMEORIGIN
   12 ObjHeader    c Referrer-Policy: strict-origin-when-cross-origin
   12 ObjHeader    c Content-Encoding: gzip
   12 ObjHeader    c Content-Type: text/html; charset=UTF-8
   12 Gzip         c u F - 26 0 80 128 138
   12 VCL_call     c deliver deliver
   12 TxProtocol   c HTTP/1.1
   12 TxStatus     c 200
   12 TxResponse   c OK
   12 TxHeader     c Server: Apache/2.2.15 (CentOS)
   12 TxHeader     c X-Robots-Tag: noindex
   12 TxHeader     c X-Content-Type-Options: nosniff
   12 TxHeader     c Expires: Wed, 11 Jan 1984 05:00:00 GMT
   12 TxHeader     c Cache-Control: no-cache, must-revalidate, max-age=0
   12 TxHeader     c X-Frame-Options: SAMEORIGIN
   12 TxHeader     c Referrer-Policy: strict-origin-when-cross-origin
   12 TxHeader     c Content-Encoding: gzip
   12 TxHeader     c Content-Type: text/html; charset=UTF-8
   12 TxHeader     c Content-Length: 26
   12 TxHeader     c Accept-Ranges: bytes
   12 TxHeader     c Date: Fri, 04 Mar 2022 20:20:58 GMT
   12 TxHeader     c X-Varnish: 1374630903
   12 TxHeader     c Via: 1.1 varnish
   12 TxHeader     c Connection: close
   12 TxHeader     c X-Age: 0
   12 TxHeader     c X-Cache: MISS
   12 TxHeader     c X-Pragma: 
   12 TxHeader     c X-Cache-Control: 
   12 TxHeader     c X-Stock: 
   12 TxHeader     c X-URL: /do_ajax.php?action=get-dom
   12 TxHeader     c X-Auth: 
   12 TxHeader     c X-IP: 
   12 Length       c 26
   12 ReqEnd       c 1374630903 1646425257.592263222 1646425258.176410437 0.000068903 0.584094763 0.000052452
   12 SessionClose c Connection: close

所以我调试了一下,发现 varnish 正在执行缓存查找,但结果返回了一个命中通过的对象。但在阅读了以下内容后: https://stackoverflow.com/questions/12691489/varnish-hit-for-pass-means如果我理解正确的话,我发现由于流量太大它没有缓存,有没有办法强制清漆缓存对象?

我看到了类似这些东西,但我不确定如何在我的清漆配置中覆盖它:

   12 TxHeader     c Expires: Wed, 11 Jan 1984 05:00:00 GMT

刚刚看到这个,但除了确定问题可能是什么之外,它并没有帮助我:

https://stackoverflow.com/questions/35449723/varnish-what-is-causing-hit-for-pass

答案1

您的后端返回一个Cache-Control: no-cache, must-revalidate, max-age=0标头,明确告诉 Varnish 不要缓存。

我最初的建议是确保/do_ajax.php?action=get-dom资源返回Cache-Control允许缓存的标头。

如果不可能的话,您可以始终使用以下 VCL 代码来强制缓存:

sub vcl_backend_response {
    if(bereq.url == "/do_ajax.php?action=get-dom") {
        unset beresp.http.Expires;
        set beresp.http.Cache-control = "public, max-age=3600";
        set beresp.ttl = 1h;
        return(deliver);
    }
}

重要的:根据varnishlog命令的输出,我可以看到你正在使用过时的 Varnish 版本。你能确保你使用的是 Varnish 6 或 7 吗?请参阅https://www.varnish-software.com/developers/downloads/了解下载和安装说明。

相关内容