Last active
December 10, 2015 13:48
-
-
Save ecoad/4443239 to your computer and use it in GitHub Desktop.
Bread vcl with banning and purging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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