Skip to content

Instantly share code, notes, and snippets.

Created April 11, 2010 00:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/362401 to your computer and use it in GitHub Desktop.
Save anonymous/362401 to your computer and use it in GitHub Desktop.
backend default {
.host = "127.0.0.1";
.port = "8080";
// No more than 30% of requests should take more than 20s.
.probe = {
.url = "/";
.timeout = 30s;
.window = 10;
.threshold = 3;
}
}
// Allowed addresses
// RocketFuel "74.66.21.153";
acl bypass {
"localhost";
"12.105.18.195";
"174.143.146.127";
"173.45.234.243";
"172.16.117.101";
"172.16.117.102";
"172.16.117.103";
"172.16.117.105";
"m217701vwbs2001.pnj1.attens.net";
"m217701vwbs2002.pnj1.attens.net";
"m217701vwbs2003.pnj1.attens.net";
"m217701vwbs2004.pnj1.attens.net";
"m217701vwbs2005.pnj1.attens.net";
}
sub vcl_recv {
set req.backend = default;
if (req.request != "GET" &&
req.request != "HEAD" &&
req.request != "PUT" &&
req.request != "POST" &&
req.request != "TRACE" &&
req.request != "OPTIONS" &&
req.request != "DELETE") {
pipe;
}
// Normalize Accept-Encoding
if (req.http.Accept-Encoding ~ "gzip") {
set req.http.Accept-Encoding = "gzip";
}
else {
unset req.http.Accept-Encoding;
}
if (req.url ~ "supercron.php" || req.url ~ "cron.php") {
set req.http.X-Cron = "TRUE";
unset req.http.Cookie;
lookup;
}
// Bypass Varnish for API requests
remove req.http.X-Bypass-Auth;
if (client.ip ~ bypass && req.http.User-Agent ~ "Drupal") {
set req.http.X-Bypass-Auth = "1";
pass;
}
// Strip all cookies and look up for static assets
if (req.url ~ "^/sites/" || req.url ~ "^/misc/") {
set req.http.X-Static = "TRUE";
unset req.http.Cookie;
lookup;
}
if (req.url ~ "^/user/?$" || req.url ~ "/user/password/?$" || req.url ~ "/user/register/?$") {
set req.http.X-User-Login = "1";
pass;
}
set req.http.X-Static = "FALSE";
// Bypass Varnish for users with sessions
if (req.http.Cookie ~ "SESS") {
set req.http.X-Session = "TRUE";
pass;
}
// At this point:
// * Request is not for the API
// * Request is not for a static asset
// * Client does not have a session
set req.grace = 1h;
set req.http.X-Session = "FALSE";
unset req.http.Cookie;
lookup;
### mobile redirects - we error the request into vcl_error for the 302 redirect
if ( req.http.user-agent ~ "(.*Blackberry.*|.*BlackBerry.*|.*Blazer.*|.*Ericsson.*|.*htc.*|.*Huawei.*|.*iPhone.*|.*iPod.*)"
&& req.http.host ~ "(mlsw.mlssoccer.com)
&& req.url == "/") {
set req.http.newhost = regsub(req.http.host, "(mlsw)?\.(.*)", "http://m.mlssoccer.com");
error 750 req.http.newhost;
}
sub vcl_fetch {
if (!obj.cacheable) {
pass;
}
// Temporarily override the cache time for normal pages.
if (obj.http.Cache-Control ~ "^public,") {
set obj.http.Cache-Control = "public, max-age = 300";
set obj.ttl = 15m;
if (req.url ~ "^/matchcenter") {
set obj.http.Cache-Control = "public, max-age = 1";
set obj.http.X-Match-Center = "TRUE";
set obj.ttl = 1s;
}
}
set obj.grace = 1h;
deliver;
}
sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Varnish-Cache = "HIT";
}
else {
set resp.http.X-Varnish-Cache = "MISS";
}
}
### when the mobile feeds reach here, we just "error" it and it dishes out the 302
sub vcl_error {
if (obj.status == 750) {
set obj.http.Location = obj.response;
set obj.status = 302;
deliver;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment