Created
November 3, 2010 18:55
-
-
Save onyxfish/661517 to your computer and use it in GitHub Desktop.
Elections Center Varnish Configuration File
This file contains hidden or 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 app1 { | |
.host = "1.1.1.1"; | |
.port = "80"; | |
} | |
backend app2 { | |
.host = "2.2.2.2"; | |
.port = "80"; | |
} | |
backend app3 { | |
.host = "3.3.3.3"; | |
.port = "80"; | |
} | |
backend app4 { | |
.host = "4.4.4.4"; | |
.port = "80"; | |
} | |
acl purge { | |
"127.0.0.1"; | |
"1.1.1.1"; | |
"2.2.2.2"; | |
"3.3.3.3"; | |
"4.4.4.4"; | |
} | |
director FourPlayer random { | |
{ | |
.backend = app1; | |
.weight = 1; | |
} | |
{ | |
.backend = app2; | |
.weight = 1; | |
} | |
{ | |
.backend = app3; | |
.weight = 1; | |
} | |
{ | |
.backend = app4; | |
.weight = 1; | |
} | |
} | |
sub vcl_recv { | |
set req.backend = TwoPlayer; | |
# Filter PURGE requests | |
if (req.request == "PURGE") { | |
if(!client.ip ~ purge) { | |
error 405 "Not allowed."; | |
} | |
# Purge URLs matching a regex | |
purge("req.url ~ " req.url " && req.http.host == " req.http.host); | |
error 200 "Purged"; | |
} | |
# Don't cache POSTSs | |
if(req.request == "POST") { | |
return(pass); | |
} | |
# Only cache elections | |
if (!(req.http.host ~ "^(www.)?elections\.chicagotribune\.com" || | |
req.http.host ~ "^(www.)?elections\.apps\.chicagotribune\.com" || | |
req.http.host ~ "^elections-new\.tribapps\.com")) { | |
return(pass); | |
} | |
# Allow uncached access to the admin | |
if (req.url ~ "^/admin") { | |
return(pass); | |
} | |
# Normalize Accept-Encoding to reduce vary | |
if (req.http.Accept-Encoding) { | |
if (req.http.User-Agent ~ "MSIE 6") { | |
unset req.http.Accept-Encoding; | |
} elsif (req.http.Accept-Encoding ~ "gzip") { | |
set req.http.Accept-Encoding = "gzip"; | |
} elsif (req.http.Accept-Encoding ~ "deflate") { | |
set req.http.Accept-Encoding = "deflate"; | |
} else { | |
unset req.http.Accept-Encoding; | |
} | |
} | |
# Strip cookies | |
unset req.http.cookie; | |
# Don't respect pragma: no-cache or Cache-Control: no-cache | |
unset req.http.Pragma; | |
unset req.http.Cache-Control; | |
# Enable a one-minute grace period: http://www.varnish-cache.org/wiki/VCL#Grace | |
set req.grace = 1m; | |
} | |
sub vcl_fetch { | |
# Don't cache POSTSs | |
if(req.request == "POST") { | |
return(pass); | |
} | |
# Only cache elections | |
if (!(req.http.host ~ "^(www.)?elections\.chicagotribune\.com" || | |
req.http.host ~ "^(www.)?elections\.apps\.chicagotribune\.com" || | |
req.http.host ~ "^elections-new\.tribapps\.com")) { | |
return(pass); | |
} | |
# Allow uncached access to the admin | |
if (req.url ~ "^/admin") { | |
return(pass); | |
} | |
# Don't cache things which specifically say not to | |
if (beresp.http.Cache-Control ~ "no-cache") { | |
return(pass); | |
} | |
# Process Edge-side includes | |
esi; | |
# Strip cookies | |
unset beresp.http.Set-Cookie; | |
# Enable a one-minute grace period: http://www.varnish-cache.org/wiki/VCL#Grace | |
set req.grace = 1m; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment