Skip to content

Instantly share code, notes, and snippets.

@FrankM1
Forked from willmot/wordpress.vcl
Created May 6, 2013 00:31
Show Gist options
  • Save FrankM1/5522722 to your computer and use it in GitHub Desktop.
Save FrankM1/5522722 to your computer and use it in GitHub Desktop.
backend default {
.host = "127.0.0.1";
.port = "8444";
}
sub vcl_recv {
# Allow the back-end to serve up stale content if it is responding slowly.
set req.grace = 2m;
# Always cache the following file types for all users.
if ( req.url ~ "(?i)\.(png|gif|jpeg|jpg|ico|swf|css|js|html|htm)(\?[a-z0-9]+)?$" ) {
unset req.http.cookie;
}
# Don't serve cached pages to logged in users
if ( req.http.cookie ~ "wordpress_logged_in" || req.url ~ "vaultpress=true" ) {
return( pass );
}
# Drop any cookies sent to WordPress.
if ( ! ( req.url ~ "wp-(login|admin)" ) ) {
unset req.http.cookie;
}
# Handle compression correctly. Different browsers send different
# "Accept-Encoding" headers, even though they mostly all support the same
# compression mechanisms. By consolidating these compression headers into
# a consistent format, we can reduce the size of the cache and get more hits.
# @see: http://varnish.projects.linpro.no/wiki/FAQ/Compression
if ( req.http.Accept-Encoding ) {
if ( req.http.Accept-Encoding ~ "gzip" ) {
# If the browser supports it, we'll use gzip.
set req.http.Accept-Encoding = "gzip";
}
else if ( req.http.Accept-Encoding ~ "deflate" ) {
# Next, try deflate if it is supported.
set req.http.Accept-Encoding = "deflate";
}
else {
# Unknown algorithm. Remove it and send unencoded.
unset req.http.Accept-Encoding;
}
}
}
sub vcl_fetch {
# Allow items to be stale if needed.
set beresp.grace = 2m;
# Drop any cookies WordPress tries to send back to the client.
if ( ! req.url ~ "wp-(login|admin)" && ! req.http.cookie ~ "wordpress_logged_in" ) {
unset beresp.http.set-cookie;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment