WordPress Varnish VCL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
I'm a newbie with this, but...
Seems to me like you are only dropping WP-cookies, wouldn't be better to kill all cookies ?
Varnish does not cache content with cookies, so if I am to add a Google Analytics-string it would be for nothing that I have the cache... (?)
Found this:
and this:
sub vcl_recv {
admin users always miss the cache
if( req.url ~ "^/wp-(login|admin)" || req.http.Cookie ~ "wordpress_logged_in_" ){
return (pass);
}
ignore any other cookies
unset req.http.Cookie;
return (lookup);
}