-
-
Save vincentkoc/8015352 to your computer and use it in GitHub Desktop.
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 = "8080"; | |
} | |
acl purge { | |
"localhost", | |
"69.195.222.132" | |
} | |
sub vcl_recv { | |
# Allow purging | |
if(req.request == PURGE){ | |
if(!client.ip ~ acl){ | |
error 405 "Purging not allowed."; | |
} | |
return(lookup); | |
} | |
# 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; | |
} | |
} | |
sub vcl_miss { | |
if(req.request == PURGE){ | |
purge; | |
error 200 "Purged"; | |
} | |
} | |
sub vcl_hit { | |
if(req.request == PURGE){ | |
purge; | |
error 200 "Purged"; | |
} | |
} | |
sub vcl_deliver { | |
if(obj.hits > 0) { | |
set resp.http.X-Varnish-Cache = "HIT ("+obj.hits+")"; | |
} else { | |
set resp.http.X-Varnish-Cache = "MISS"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment