Skip to content

Instantly share code, notes, and snippets.

@darron
Created April 29, 2010 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darron/384412 to your computer and use it in GitHub Desktop.
Save darron/384412 to your computer and use it in GitHub Desktop.
/* Set the backend / origin server. */
backend default {
.host = "hostname.of.website";
.port = "80";
/* Probe for healthiness of backend. */
/* After 8 passing requests, it marks it as available. */
.probe = {
.url = "/probe.html";
.timeout = 5 s;
.interval = 10 s;
.window = 10;
.threshold = 8;
.initial = 10;
}
}
sub vcl_recv {
/* Set the Host header of the backend */
set req.http.Host = "hostname.of.website";
if (req.backend.healthy) {
/* 5 minutes TTL on all content */
set req.grace = 300s;
} else {
/* If you can't get to the backend - 1 hour grace. */
set req.grace = 1h;
}
/* If it's a strange request - pipe it through. */
if (req.request != "GET" &&
req.request != "HEAD" &&
req.request != "PUT" &&
req.request != "POST" &&
req.request != "TRACE" &&
req.request != "OPTIONS" &&
req.request != "DELETE") {
/* Non-RFC2616 or CONNECT which is weird. */
return (pipe);
}
/* We only deal with GET and HEAD by default */
if (req.request != "GET" && req.request != "HEAD") {
return (pass);
}
/* If they request the CMS - send them to the backend directly. */
if (req.request == "GET" && req.url ~ "^/cms-directory/") {
error 750 "Moved Temporarily";
}
return(lookup);
}
sub vcl_error {
if (obj.status == 750) {
set obj.http.Location = "http://hostname.of.website/cms-directory/";
set obj.status = 302;
return(deliver);
}
}
sub vcl_fetch {
/* 5 minutes TTL on all content */
set beresp.ttl = 300s;
/* If you can't get to the backend - 1 hour grace. */
set beresp.grace = 1h;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment