Skip to content

Instantly share code, notes, and snippets.

@barek2k2
Created May 5, 2013 14:40
Show Gist options
  • Save barek2k2/5520990 to your computer and use it in GitHub Desktop.
Save barek2k2/5520990 to your computer and use it in GitHub Desktop.
varnish configuration
/etc/varnish/default.vcl
backend default {
.host = "127.0.0.1";
.port = "8080";
}
acl purge {
"localhost";
}
sub vcl_recv {
if (req.request == "PURGE") {
if(!client.ip ~ purge) {
error 405 "Not allowed.";
}
purge("req.url ~ ^" req.url "$ && req.http.host == "req.http.host);
}
}
sub vcl_recv {
#Clears all caches if requesting method is post or put or delete
if (req.request == "POST" || req.request == "PUT" || req.request == "DELETE") {
purge("req.url == " req.url " && req.http.host == " req.http.host);
}
}
sub vcl_fetch {
# Make cache for all get request
if (req.request == "GET") {
unset beresp.http.Set-Cookie;
set beresp.cacheable = true;
set beresp.ttl = 60m;
}
if (req.url ~ "^/images/" || req.url ~ "^/javascripts" || req.url ~ "^/stylesheets"){
set beresp.ttl = 60m;
}
}
/etc/default/varnish
DAEMON_OPTS="-a :80 \
-T localhost:6082 \
-f /etc/varnish/default.vcl \
-S /etc/varnish/secret \
-s file,/var/lib/varnish/$INSTANCE/varnish_storage.bin,1G"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment