We are using below code in 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
We are using below code in 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
For help with Fastly Varnish/VCL I recommend reading through both:
I would also generally recommend reaching out to support@fastly.com (they're a good group of people).
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.
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.
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:
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):
sub vcl_recv {
#FASTLY recv
if (req.restarts > 0) {
if (<some_condition>) {
// do something
}
}
}