Skip to content

Instantly share code, notes, and snippets.

@n1zyy
Created December 25, 2011 02:49
Show Gist options
  • Save n1zyy/1518659 to your computer and use it in GitHub Desktop.
Save n1zyy/1518659 to your computer and use it in GitHub Desktop.
Sample varnish.vcl
acl purge {
"localhost";
"127.0.0.1";
}
#backend default {
# .host = "127.0.0.1";
# .port = "8080";
#}
backend blogs {
.host = "blogs.n1zyy.com";
.port = "8080";
}
backend aml {
.host = "www.amherstmusiclessons.com";
.port = "8080";
}
sub vcl_recv {
# Clear Google Analytics cookies
if (req.http.Cookie) {
set req.http.Cookie = regsuball(req.http.Cookie, "(^|; ) *__utm.=[^;]+;? *", "\1");
if (req.http.Cookie == "") {
remove req.http.Cookie;
}
# Honestly, I don't fully understand how virtual hosting works with varnish
# This might not be necessary
if (req.http.host ~ "blogs.n1zyy.com") {
set req.backend = blogs;
} else if (req.http.host ~ "amherstmusiclessons.com") {
set req.backend = aml;
}
}
# I think this is standard and not required
if (req.request != "GET" && req.request != "HEAD") {
return (pass);
}
# Support PURGEing of pages
if (req.request == "PURGE") {
if (!client.ip ~ purge) {
error 405 "Permission denied";
}
return (lookup);
}
}
# Just defined for PURGE support
sub vcl_hit {
if (req.request == "PURGE") {
purge_url(req.url);
error 200 "Purged";
}
}
# Just here for PURGE support
sub vcl_miss {
if (req.request == "PURGE") {
purge_url(req.url);
error 200 "Purged (miss).";
}
}
# Insert a header indicating whether it was a hit or miss
sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Cache = "Cache hit";
} else {
set resp.http.X-Cache = "Cache miss";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment