Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- backend default {
- .host = "127.0.0.1";
- .port = "8080";
- }
- acl purge {
- "127.0.0.1";
- "localhost";
- "hidden.tld";
- "www.hidden.tld";
- }
- include "/opt/local/etc/varnish/purge.vcl";
- sub vcl_recv {
- 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;
- }
- }
- if (req.restarts == 0) {
- if (req.http.x-forwarded-for) {
- set req.http.X-Forwarded-For =
- req.http.X-Forwarded-For + ", " + client.ip;
- } else {
- set req.http.X-Forwarded-For = client.ip;
- }
- }
- # Don't serve cached pages to logged in users
- if ( req.http.cookie ~ "wordpress_logged_in" || req.url ~ "vaultpress=true" ) {
- return( pass );
- }
- if (!(req.url ~ "wp-(login|admin)") &&
- !(req.url ~ "&preview=true" ) ) {
- unset req.http.cookie;
- }
- if (req.request != "GET" &&
- req.request != "HEAD" &&
- req.request != "PUT" &&
- req.request != "POST" &&
- req.request != "TRACE" &&
- req.request != "OPTIONS" &&
- req.request != "DELETE") {
- return (pipe);
- }
- # Do not cache these paths
- if (req.url ~ "^/wp-cron\.php$" ||
- req.url ~ "^/xmlrpc\.php$" ||
- req.url ~ "^/wp-admin/.*$" ||
- req.url ~ "^/wp-login.php.*$" ||
- req.url ~ "^/wp-includes/.*$" ||
- req.url ~ "\?s=") {
- return (pass);
- }
- if (req.request != "GET" && req.request != "HEAD") {
- return (pass);
- }
- # if (!(req.url ~ "wp-(login|admin)") &&
- # !(req.url ~ "&preview=true" ) ) {
- # unset req.http.cookie;
- # }
- if (req.http.Authorization || req.http.Cookie) {
- return (pass);
- }
- return (lookup);
- }
- sub vcl_fetch {
- # remove some headers we never want to see
- unset beresp.http.Server;
- unset beresp.http.X-Powered-By;
- if (! (req.url ~ "wp-(login|admin)") &&! req.http.cookie ~ "wordpress_logged_in|resetpass") {
- #if (!(req.url ~ "wp-(login|admin)")) {
- unset beresp.http.set-cookie;
- set beresp.ttl = 96h;
- set beresp.grace = 1w;
- }
- # don't cache response to posted requests or those with basic auth
- if ( req.request == "POST" || req.http.Authorization ) {
- return (hit_for_pass);
- }
- # don't cache search results
- if( req.url ~ "\?s=" ){
- return (hit_for_pass);
- }
- # only cache status ok
- if ( beresp.status != 200 ) {
- return (hit_for_pass);
- }
- if (beresp.ttl <= 0s ||
- beresp.http.Set-Cookie ||
- beresp.http.Vary == "*") {
- set beresp.ttl = 120 s;
- return (hit_for_pass);
- }
- return (deliver);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement