Skip to content

Instantly share code, notes, and snippets.

@haifeng
Created November 7, 2013 20:51
Show Gist options
  • Save haifeng/7361661 to your computer and use it in GitHub Desktop.
Save haifeng/7361661 to your computer and use it in GitHub Desktop.
vcl
backend F_default {
.host = "origin-imgry.pressly.com";
.port = "80";
}
backend F_s3_host {
.host = "imgrydb.pressly.com.s3.amazonaws.com";
.port = "80";
}
sub vcl_recv {
set req.backend = F_default;
if( req.http.host == "imgrydb.pressly.com" ) {
set req.backend = F_s3_host;
}
if (req.restarts == 0) {
if (req.http.x-forwarded-for) {
set req.http.X-Forwarded-For = req.http.X-Forwarded-For + ", " + client.ip;
} else {
set req.http.X-Forwarded-For = client.ip;
}
}
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);
}
if (req.request != "GET" && req.request != "HEAD") {
/* We only deal with GET and HEAD by default */
return (pass);
}
if (req.http.Authorization || req.http.Cookie) {
/* Not cacheable by default */
return (pass);
}
return (lookup);
}
sub vcl_fetch {
if (beresp.status == 302) {
set beresp.ttl = 3600 s;
set beresp.http.X-Need-Restart = "1";
return (deliver);
}
return (deliver);
}
sub vcl_deliver {
if (resp.http.X-Need-Restart == "1") {
unset resp.http.X-Need-Restart;
set resp.http.location = regsub(resp.http.location,"^http://","");
set req.http.host = regsub(resp.http.location,"/.*$","");
set req.url = regsub(resp.http.location,"^[^/]*","");
return(restart);
}
return (deliver);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment