Skip to content

Instantly share code, notes, and snippets.

@ecoad
Last active December 10, 2015 13:48
Show Gist options
  • Save ecoad/4443239 to your computer and use it in GitHub Desktop.
Save ecoad/4443239 to your computer and use it in GitHub Desktop.
Bread vcl with banning and purging
backend tcutshortlist {
.host = "tcut-shortlist.coad.me";
.port = "8080";
}
backend tcutstylist {
.host = "tcut-stylist.coad.me";
.port = "8080";
}
backend coadme {
.host = "coad.me";
.port = "8080";
}
acl purgers {
"127.0.0.1";
}
sub vcl_recv {
if (req.request == "PURGE") {
if (!client.ip ~ purgers) {
error 405 "Method not allowed";
}
return (lookup);
}
if (req.request == "BAN") {
if (!client.ip ~ purgers) {
error 405 "Method not allowed";
}
ban_url(req.url);
error 200 "Banned";
}
if (req.request != "GET" && req.request != "HEAD") {
/* We only deal with GET and HEAD by default */
return (pass);
}
if (req.http.host == "tcut-stylist.coad.me") {
set req.backend = tcutstylist;
return (lookup);
}
if (req.http.host == "tcut-shortlist.coad.me") {
set req.backend = tcutshortlist;
return (lookup);
}
if (req.http.host == "coad.me") {
set req.backend = coadme;
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";
}
}
sub vcl_pass {
if (req.request == "PURGE") {
error 502 "PURGE on a passed object";
}
}
sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment