Created
October 23, 2013 10:39
-
-
Save roflmao/7116338 to your computer and use it in GitHub Desktop.
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
ub vcl_recv { | |
if (req.backend.healthy) { | |
set req.grace = 5m; | |
} else { | |
set req.grace = 1h; | |
} | |
if ( req.url ~ "/static/" ) { | |
unset req.http.Cookie; | |
return(lookup); | |
} | |
else { | |
return(pass); | |
} | |
# Remove cookies from most kinds of static objects | |
if (req.url ~ "(?i)\.(png|gif|jpeg|jpg|ico|swf|css|js|html|htm|woff|ttf|eot|svg)(\?[a-zA-Z0-9\=\.\-]+)?$") { | |
remove req.http.Cookie; | |
} | |
# Remove Google Analytics and Piwik cookies everywhere | |
if (req.http.Cookie) { | |
set req.http.Cookie = regsuball(req.http.Cookie, "(^|;\s*)(__[a-z]+|has_js)=[^;]*", ""); | |
set req.http.Cookie = regsuball(req.http.Cookie, "(^|;\s*)(_pk_(ses|id)[\.a-z0-9]*)=[^;]*", ""); | |
} | |
if (req.http.Cookie == "") { | |
remove req.http.Cookie; | |
} | |
} | |
sub vcl_pass { | |
set bereq.http.connection = "close"; | |
} | |
sub vcl_fetch { | |
set beresp.grace = 60m; | |
set beresp.ttl = 86400s; | |
# Strip cookies before static items are inserted into cache. | |
if (req.url ~ "\.(png|gif|jpg|swf|css|js|ico|html|htm|woff|eof|ttf|svg)$") { | |
remove beresp.http.set-cookie; | |
} | |
} | |
sub vcl_deliver { | |
if (obj.hits > 0) { | |
set resp.http.X-Cache = "HIT"; | |
set resp.http.X-Cache-Hits = obj.hits; | |
} else { | |
set resp.http.X-Cache = "MISS"; | |
} | |
set resp.http.X-Served-By = server.hostname; | |
# Remove the Varnish header | |
remove resp.http.X-Varnish; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment