# Varnish configuration for wordpress
# AdminGeekZ Ltd <[email protected]>
# URL: www.admingeekz.com/varnish-wordpress
# Version: 1.5
## updated -> Brad Tarver
## updated -> for Varnish 4.0 syntax
vcl 4.0;
backend default {
.host = "127.0.0.1";
.port = "8080";
}
#Which hosts are allowed to PURGE the cache
acl purge {
"172.31.27.119";
}
sub vcl_recv {
if (req.method == "BAN") {
if(!client.ip ~ purge) {
return (synth(405, "Not allowed."));
}
ban("req.url ~ "+req.url+" && req.http.host == "+req.http.host);
return (synth(200, "Banned."));
}
if (req.method != "GET" &&
req.method != "HEAD" &&
req.method != "PUT" &&
req.method != "POST" &&
req.method != "TRACE" &&
req.method != "OPTIONS" &&
req.method != "DELETE") {
return (pipe);
}
if (req.method != "GET" && req.method != "HEAD") {
return (pass);
}
#Don't cache admin or login pages
if (req.url ~ "wp-(login|admin)" ||
req.url ~ "preview=true" ||
req.url ~ "contact-form") {
return (pass);
}
#Don't cache logged in users
if (req.http.Cookie && req.http.Cookie ~ "(wordpress_|wordpress_logged_in|comment_author_)") {
return(pass);
}
#Don't cache ajax requests, urls with ?nocache or comments/login/regiser
if(req.http.X-Requested-With == "XMLHttpRequest" || req.url ~ "nocache" || req.url ~ "(control.php|wp-comments-post.php|wp-login.php|register.php)") {
return (pass);
}
if (req.http.host == "(www.)oncallnetworks.net") {
set req.backend_hint = default;
}
if (req.http.host == "(www.)liveoakpsych.com") {
set req.backend_hint = default;
}
if (req.http.host == "(www.)brandonfc.com") {
set req.backend_hint = default;
}
if (req.http.host == "(www.)adaptingtechnologies.com") {
set req.backend_hint = default;
}
if (req.http.host == "(www.)stalexisjackson.org") {
set req.backend_hint = default;
}
if (req.http.host == "(www.)lugoj.org") {
set req.backend_hint = default;
}
if (req.http.host == "(www.)berial.org") {
set req.backend_hint = default;
}
# redirect berial.info/.net to .org using vcl_synth
if ( (req.http.host ~ "^(?i)www.berial.net" || req.http.host ~ "^(?i)berial.net" || req.http.host ~ "^(?i)www.berial.info" || req.http.host ~ "^(?i)berial.info") ) {
return (synth(750, ""));
}
if (req.http.host == "mlg.oncallnetworks.net" ) {
set req.backend_hint = default;
}
if (req.http.host == "(www.)idl[e3]mind.net" ) {
set req.backend_hint = default;
}
if (req.http.host == "(www.)badmojobrew\bery|ing|ingco\b.com" ) {
set req.backend_hint = default;
}
#Serve stale cache objects for up to 2 minutes if the backend is down
set req.http.grace = 120;
#Remove all cookies if none of the above match
unset req.http.cookie;
return (hash);
}
sub vcl_synth {
if (resp.status == 750) {
set resp.status = 301;
# redirect berial.info/.net to .org
set resp.http.Location = "http://www.berial.org" + req.url;
return(deliver);
}
}
sub vcl_backend_response {
#Don't cache error pages
if (beresp.status >= 400) {
set beresp.ttl = 0m;
return(deliver);
}
if (bereq.url ~ "wp-(login|admin)" ||
bereq.url ~ "preview=true" ||
bereq.url ~ "contact-form") {
set beresp.uncacheable = true;
set beresp.ttl = 120s;
return (deliver);
}
if (bereq.http.Cookie ~"(wp-postpass|wordpress_logged_in|comment_author_)") {
set beresp.uncacheable = true;
set beresp.ttl = 120s;
return (deliver);
}
#Set the default cache time of 12 hours
set beresp.ttl = 12h;
return (deliver);
}
sub vcl_hash {
#Uncomment if you use multiple domains/subdomains and want to maintain separate caches
#hash_data(req.http.host);
#Uncomment if you use SSL and want to maintain separate caches
#hash_data(req.http.X-Forwarded-Port);
#Set the hash to include the cookie if it exists, to maintain per user cache
if ( req.http.Cookie ~"(wp-postpass|wordpress_logged_in|comment_author_)" ) {
hash_data(req.http.Cookie);
}
}
#Comment this out if you don't want to see whether there was a HIT or MISS in the headers
sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
}
Comments
0 B
|👍
/👎
0 B
|👍
/👎