在vcl_hash中,我有
backend default {
.host = "127.0.0.1";
.port = "8080";
}
acl purge {
"localhost";
}
sub vcl_hash {
if(req.http.Cookie ~ "isLogin") {
hash_data("1");
}
}
sub vcl_recv {
if (req.request == "PURGE") {
if (!client.ip ~ purge) {
error 405 "Not allowed.";
}
return (lookup);
}
return(lookup);
}
sub vcl_hit {
if (req.request == "PURGE") {
purge;
error 200 "Purged.";
}
}
sub vcl_miss {
if (req.request == "PURGE") {
purge;
error 404 "Not in Cache.";
}
}我正在使用下面的命令来清除urls。curl -X PURGE http://release.com/user/details
如果为已登出的用户缓存url,我会得到以下输出
curl -X PURGE http://release.com/user/details
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>200 Purged.</title>
</head>
<body>
<h1>Error 200 Purged.</h1>
<p>Purged.</p>
<h3>Guru Meditation:</h3>
<p>XID: 1071483546</p>
<hr>
<p>Varnish cache server</p>
</body>
</html>如果它只为已登录的用户缓存,我总是得到下面的输出。(即使url正在制造“点击”)
curl -X PURGE http://release.com/user/details
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>404 Not in Cache.</title>
</head>
<body>
<h1>Error 404 Not in Cache.</h1>
<p>Not in Cache.</p>
<h3>Guru Meditation:</h3>
<p>XID: 998719206</p>
<hr>
<p>Varnish cache server</p>
</body>
</html>根据用户是否登录,http://release.com/user/details看起来会有所不同。(即它有没有isLogin cookie )。清除不适用于在vcl_hash中进行哈希处理的urls。似乎是Varnish的错误或特征。请建议,可以做些什么。
发布于 2016-05-25 02:27:44
我发现了我的问题,可能对你和任何使用带有purge的vcl_hash的人都是一样的。散列用于清除,因此用于has散列的所有请求信息都将存在以进行清除。在您的示例中,您将检查cookie if(req.http.Cookie ~ "isLogin"),因此您必须将此cookie与清除请求一起发送,如下所示:
curl -X PURGE --cookie "isLogin=1" http://release.com/user/details如果您想清除散列的所有变体,则需要调用它两次,一次使用cookie,另一次不使用。
发布于 2018-04-10 19:37:31
我们有一个类似的场景。我们希望为移动和桌面用户提供不同的内容(取决于用户代理)。
我们是在不改变对象散列的情况下这样做的。我们正在使用同一对象的不同变体(不同)。阅读cache invalidation documentation。
我们使用在beresp.http.Vary中添加的自定义标头(我们也在后端使用此自定义标头)。
在我们的场景中,必须设置发送回用户(包括Google)的Vary标头,以便他们知道响应依赖于User-Agent。我们在vcl_deliver中这样做。
sub vcl_recv {
...
if (req.restarts == 0) {
# Change this code, we are using a CloudFront header
if (req.http.CloudFront-Is-Mobile-Viewer == "true") {
set req.http.X-Device-Type = "mobile";
} else {
set req.http.X-Device-Type = "desktop";
}
}
...
if (req.method == "PURGE") {
if (!client.ip ~ acl_purge) {
return(synth(400, "Bad request."));
}
return(purge);
}
...
}
sub vcl_backend_response {
...
if (beresp.http.Vary) {
set beresp.http.Vary = beresp.http.Vary + ", " + "X-Device-Type";
} else {
set beresp.http.Vary = "X-Device-Type";
}
...
}
sub vcl_deliver {
...
set resp.http.Vary = "Accept-Encoding, User-Agent";
...
}https://stackoverflow.com/questions/25470449
复制相似问题