gpt4 book ai didi

Varnish ,是什么原因造成撞球?

转载 作者:行者123 更新时间:2023-12-03 17:47:05 25 4
gpt4 key购买 nike

这是varnishlog(已编辑-展开以提供更多信息):

*   << Request  >> 172651    
- Begin req 172650 rxreq
- Timestamp Start: 1455791132.581465 0.000000 0.000000
- Timestamp Req: 1455791132.581465 0.000000 0.000000
- ReqStart 127.0.0.1 47991
- ReqMethod GET
- ReqURL /
- ReqProtocol HTTP/1.1
- ReqHeader X-Real-IP: x.x.x.x
- ReqHeader X-Forwarded-For: x.x.x.1, x.x.x.2
- ReqHeader X-Forwarded-Proto: https
- ReqHeader X-Forwarded-Port: 443
- ReqHeader Host: mydomain.com
- ReqHeader User-Agent: Go-http-client/1.1 (//benchmark app, but regular browser client happens the same
- ReqHeader Cf-Connecting-Ip: x.x.x.x
- ReqHeader Cf-Ipcountry: AND
- ReqHeader Cf-Origin-Https: off
- ReqHeader Cf-Ray: 27690752ab232e21-NRT
- ReqHeader Cf-Visitor: {"scheme":"https"}
- ReqUnset X-Forwarded-For: x.x.x.1, x.x.x.2
- ReqHeader X-Forwarded-For: x.x.x.ext, x.x.x.1, x.x.x.2
- VCL_call RECV
- VCL_return hash
- VCL_call HASH
- VCL_return lookup
- Debug "XXXX HIT-FOR-PASS"
- HitPass 393349
- VCL_call PASS
- VCL_return fetch
- Link bereq 172652 pass
- Timestamp Fetch: 1455791132.581733 0.000268 0.000268
- RespProtocol HTTP/1.1
- RespStatus 200
- RespReason OK
- RespHeader Server: nginx
- RespHeader Date: Thu, 18 Feb 2016 10:25:32 GMT
- RespHeader Content-Type: text/html; charset=utf-8
- RespHeader Vary: Accept-Encoding, Accept-Encoding
- RespHeader Etag: "1455788472-0"
- RespHeader Content-Language: ja
- RespHeader Cache-Control: no-cache
- RespHeader Last-Modified: Thu, 18 Feb 2016 09:41:12 GMT
- RespHeader X-Content-Options: nosniff
- RespHeader X-Micro-Cache: HIT
- RespHeader X-Varnish: 172651
- RespHeader Age: 0
- RespHeader Via: 1.1 varnish-v4
- VCL_call DELIVER
- VCL_return deliver
- Timestamp Process: 1455791132.581744 0.000279 0.000011
- RespHeader Accept-Ranges: bytes
- RespHeader Transfer-Encoding: chunked
- Debug "RES_MODE 8"
- RespHeader Connection: keep-alive
- Timestamp Resp: 1455791132.581794 0.000329 0.000049
- ReqAcct 336 0 336 436 57069 57505
- End

我已经读到,这是在设置set-cookie header 或设置cache-control:max-age = 0时创建的。

好吧,我在我的子vcl_backend_response中有此操作,试图避免命中率。这很不礼貌,但是我不知道后端是什么原因导致此命中率的:
sub vcl_backend_response {
unset beresp.http.set-cookie;
unset beresp.http.expires;
set beresp.http.Cache-Control = "max-age=6000";
}

我摆脱了Expire,因为它已设置为时间戳0。所以我可能是这样。然后,我尝试使用Cache-control,但相同。我将以这种速率取消设置所有 header ...

毕竟是304响应,为什么不缓存呢?

更多信息:后端是Drupal应用程序。

编辑1:关于vcl_recv

是的,我确实有东西,我正在返回某些路径的通行证(不是我正在检查的路径),我正在为文件取消设置cookie,并且我正在为其余部分取消所有非drupal session 的cookie。它等于或小于复制/粘贴drupal默认子vcl_recv。如果您愿意,我可以在这里复制。

顺便说一句,我更改了其他内容,现在我在响应200中也被击中通过(但是当我使用基准测试工具时)。有人删除了说可能是由于响应304的答案。我正在检查,但答案不见了:(

好了,这里是vcl_recv:
sub vcl_recv {
if (req.url ~ "^/status\.php$" ||
req.url ~ "^/admin/.*$" ||
[...]
req.url ~ "^.*\.js.*$" )
{
return (pass);
}

if (req.url ~ "^/admin/content/backup_migrate/export") {
return (pipe);
}

## COOKIES ##
if (req.url ~ "(?i)\.(css|js|jpg|jpeg|gif|png|ico|svg|map)(\?.*)?$") {
unset req.http.Cookie;
}
if (req.http.Cookie) {
set req.http.Cookie = ";" + req.http.Cookie;
set req.http.Cookie = regsuball(req.http.Cookie, "; +", ";");
set req.http.Cookie = regsuball(req.http.Cookie, ";(SESS[a-z0-9]+|SSESS[a-z0-9]+|NO_CACHE)=", "; \1=");
set req.http.Cookie = regsuball(req.http.Cookie, ";[^ ][^;]*", "");
set req.http.Cookie = regsuball(req.http.Cookie, "^[; ]+|[; ]+$", "");
if (req.http.Cookie == "") {
unset req.http.Cookie;
}
# if any of our cookies of interest are still there, we disable caching and pass the request
else {
return (pass);
}
}
}

它几乎总是在所有http中获得通过。 304个响应和200个响应。我已经编辑了上面的varnishlog,以显示一个完整的示例以提供更多信息。

编辑:
因此,这是请求的日志,其中显示了通过命中率。肯定是将命中率设为通行证的一种:
-   ReqHeader      X-Forwarded-For: 127.0.0.1
- VCL_return hash
- VCL_call HASH
- VCL_return lookup
- VCL_call MISS
- VCL_return fetch
- Link bereq 3 fetch
- Timestamp Fetch: 1456731597.992472 0.099948 0.099948
- RespProtocol HTTP/1.1
- RespStatus 200
- RespReason OK
- RespHeader Date: Mon, 29 Feb 2016 07:39:57 GMT
- RespHeader Content-Type: text/html; charset=utf-8
- RespHeader Content-Encoding: gzip
- RespHeader Vary: Accept-Encoding
- RespHeader Etag: "1456730796-0"
- RespHeader Content-Language: ja
- RespHeader Cache-Control: no-cache
- RespHeader Last-Modified: Mon, 29 Feb 2016 07:26:36 GMT
- RespHeader Expires: Thu, 01 Jan 1970 00:00:01 GMT
- RespHeader X-Content-Options: nosniff
- RespHeader X-Micro-Cache: EXPIRED
- RespHeader X-Varnish: 2
- RespHeader Age: 0
- RespHeader Via: 1.1 varnish-v4
- RespUnset Etag: "1456730796-0"
- RespHeader ETag: W/"1456730796-0"
- VCL_call DELIVER
- RespHeader X-Cache: MISS
- RespHeader X-Cache-Hits: 0
- RespUnset X-Varnish: 2
- RespUnset Via: 1.1 varnish-v4
- VCL_return deliver
- Timestamp Process: 1456731597.992517 0.099993 0.000044
- RespUnset Content-Encoding: gzip
- RespHeader Accept-Ranges: bytes
- RespHeader Content-Length: 53980
- Debug "RES_MODE 42"
- RespHeader Connection: keep-alive
- Gzip U D - 12752 53980 80 101936 101946
- Timestamp Resp: 1456731597.992817 0.100293 0.000300
- ReqAcct 746 0 746 437 53980 54417

最佳答案

这个问题太长了,恐怕它对其他人也可能没有用。

感谢其他答案给出的链接,我看到了这一点(vcl_backend_response的默认实现):

sub vcl_backend_response {
if (beresp.ttl <= 0s ||
beresp.http.Set-Cookie ||
beresp.http.Surrogate-control ~ "no-store" ||
(!beresp.http.Surrogate-Control &&
beresp.http.Cache-Control ~ "no-cache|no-store|private") ||
beresp.http.Vary == "*") {
/*
* Mark as "Hit-For-Pass" for the next 2 minutes
*/
set beresp.ttl = 120s;
set beresp.uncacheable = true;
}
return (deliver);
}

这是所有导致通过的条件。多亏了这一点,我才知道造成通行成功的原因是beresp.ttl <= 0。

那么beres.ttl是哪个值?在同一链接上,我们读到以下内容:beresp.ttl初始化为它在以下其中找到的第一个值:
The s-maxage variable in the Cache-Control response header field
The max-age variable in the Cache-Control response header field
The Expires response header field
The default_ttl parameter.

不必修改vcl_backend_response中的 header ,因为已经设置了ttl!

很好,看一下标题,我可以从后端看到:
 -  RespHeader Expires: Thu, 01 Jan 1970 00:00:01 GMT

这是导致不及格的原因。这就是我的问题的答案。现在,为什么我不知道此 header ,那将是一个不同的问题。 (我修改了nginx并使其过期30天;到所有位置都没有结果)

关于 Varnish ,是什么原因造成撞球?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35449723/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com