Skip to content

Instantly share code, notes, and snippets.

@stormbrew
Created June 17, 2010 04:21
Show Gist options
  • Save stormbrew/441677 to your computer and use it in GitHub Desktop.
Save stormbrew/441677 to your computer and use it in GitHub Desktop.
backend neogaf_user {
.host = "php2";
.port = "80";
.max_connections = 200;
.connect_timeout = 600s;
.first_byte_timeout = 600s;
.between_bytes_timeout = 600s;
}
/*backend neogaf_guest {
.host = "php2";
.port = "80";
.max_connections = 20;
.connect_timeout = 600s;
.first_byte_timeout = 600s;
.between_bytes_timeout = 600s;
}*/
sub vcl_recv {
set req.http.host = regsub(req.http.host, "^(.+?):[0-9]+", "\1");
if (req.url ~ "^/forum/images/") {
unset req.http.cookie;
return(lookup);
}
if (req.request != "POST" && req.http.cookie !~ "bbuserid" && req.url !~ "^/forum/login.php" && req.url !~ "^/forum/register.php") {
set req.backend = neogaf_user;
if (req.http.cookie ~ "bbcache") {
set req.http.X-Should-Cache = "yes";
return(lookup);
}
} else {
set req.backend = neogaf_user;
}
set req.http.X-Should-Cache = "no";
}
sub vcl_fetch {
if (req.url ~ "\.(jpg|gif|js|css|png)$") {
set beresp.ttl = 1h;
set beresp.http.X-Image = "yes";
return(deliver);
}
if (req.http.X-Should-Cache == "yes") {
set beresp.ttl = 120s;
return(deliver); // we force it to deliver even though it sets cookies
}
}
sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT";
unset resp.http.Set-Cookie;
} else {
set resp.http.X-Cache = "MISS";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment