[英]Alternative to 'ban' for Varnish 2.x
We are using below code in Varnish 4.x :我们在Varnish 4.x中使用以下代码:
if (req.http.X-Pool) {
ban("obj.http.X-Pool ~ " + req.http.X-Pool);
}
Now we are moving to Fastly which uses Varnish 2.x , so we are not getting what is the alternative to ban in Varnish 2.x现在我们正在转向使用Varnish 2.x 的Fastly,所以我们没有得到什么是禁止在 Varnish 2.x 中的替代方案
For help with Fastly Varnish/VCL I recommend reading through both:对于 Fastly Varnish/VCL 的帮助,我建议通读以下两篇文章:
I would also generally recommend reaching out to support@fastly.com (they're a good group of people).我通常还建议联系 support@fastly.com(他们是一群很好的人)。
With regards to your question, I'm unfamiliar with bans
in standard Varnish, but reading through https://varnish-cache.org/docs/trunk/users-guide/purging.html#bans it suggests that a ban is a way to prevent cached content from being served.关于您的问题,我不熟悉标准 Varnish 中的bans
,但通过https://varnish-cache.org/docs/trunk/users-guide/purging.html#bans阅读它表明禁令是一种方式以防止提供缓存的内容。
So the solution depends on what you're trying to achieve when that happens.因此,解决方案取决于您在发生这种情况时要实现的目标。
If you just want to avoid the cache you can return a pass
from the various subroutines like vcl_recv
and vcl_hit
(although from vcl_hit will cause a hit-for-pass and so that will cause the request to go straight to the backend.如果您只想避免缓存,您可以从vcl_recv
和vcl_hit
等各种子例程返回pass
(尽管来自 vcl_hit 会导致命中传递,因此将导致请求直接发送到后端。
You could also add custom logic to either vcl_recv
or maybe even vcl_hit
(if you want to be sure the content requested was actually cached) and from there you could trigger an error
which would send you to vcl_error
where you could construct a synthetic response:您还可以将自定义逻辑添加到vcl_recv
或什至vcl_hit
(如果您想确保请求的内容实际上已缓存),然后您可以触发一个error
,该error
会将您发送到vcl_error
,您可以在其中构建合成响应:
sub vcl_hit {
#FASTLY hit
if (<some_condition>) {
error 700
}
}
sub vcl_error {
#FASTLY error
if (obj.status == 700) {
set obj.status = 404;
synthetic {"
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<h1>404 Not Found (varnish)</h1>
</body>
</html>
"};
return(deliver);
}
Alternatively from either vcl_recv
or vcl_hit
you might want to restart
and then have a check for the restart and do something different (change the backend or the request in some way):或者从vcl_recv
或vcl_hit
您可能想要restart
,然后检查重新启动并执行不同的操作(以某种方式更改后端或请求):
sub vcl_recv {
#FASTLY recv
if (req.restarts > 0) {
if (<some_condition>) {
// do something
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.