Skip to content

Instantly share code, notes, and snippets.

@bsphere
Created January 10, 2013 13:46
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 bsphere/4502139 to your computer and use it in GitHub Desktop.
Save bsphere/4502139 to your computer and use it in GitHub Desktop.
Varnish default.vcl for Node.js / Nginx
# Default backend definition. Set this to point to your content
# server.
#
backend default {
.host = "127.0.0.1";
.port = "8080";
}
sub vcl_recv {
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);
}
# force lookup for static assets
if (req.url ~ "\.(png|gif|jpg|swf|css|js|html|ico)$") {
return(lookup);
}
if (req.http.Authorization || req.http.Cookie) {
/* Not cacheable by default */
return (pass);
}
return (lookup);
}
sub vcl_fetch {
# strip the cookie before static asset is inserted into cache.
if (req.url ~ "\.(png|gif|jpg|swf|css|js|html|ico)$") {
unset beresp.http.set-cookie;
}
if (beresp.ttl <= 0s ||
beresp.http.Set-Cookie ||
beresp.http.Vary == "*") {
/*
* Mark as "Hit-For-Pass" for the next 2 minutes
*/
set beresp.ttl = 120 s;
return (hit_for_pass);
}
return (deliver);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment