Author Topic: Varnish 4 Vcl and member registration problem!  (Read 346 times)

0 Members and 1 Guest are viewing this topic.

Offline
*
Varnish 4 Vcl and member registration problem!
« on: July 16, 2017, 05:34:21 PM »
Hello, There is such a varnish file, but the member entry is not possible. I did a lot of experimentation, but I failed. What do I need to add? What do I need to help out? And the theme editing does not work ..
Systems:
Apache+nginx proxy+varnish= Wordpress
_________________________________________________________________________________________________________

# Marker to tell the VCL compiler that this VCL has been adapted to the
# new 4.0 format.
vcl 4.0;

# Default backend definition. Set this to point to your content server.
backend default {
   .host = "xxx.xxx.xxx.xxx";
   .port = "82";
   .connect_timeout = 600s;
   .first_byte_timeout = 600s;
   .between_bytes_timeout = 600s;
   .max_connections = 800;
}

backend example {
.host = "xxx.xxx.xxx.xxx.";
.port = "82";
}

import std;
include "xforward.vcl";
#include "bigfiles.vcl";
#include "mobile_cache.vcl";
#include "mobile_pass.vcl";
include "static.vcl";

sub vcl_recv {
    # Happens before we check if we have this in cache already.
    # Typically you clean up the request here, removing cookies you don't need,
    # rewriting the request, etc.
   
    if (req.http.host ~ "mysite.org") {
        set req.backend_hint = example;
    } elseif (req.http.host ~ "mysite.org") {
        set req.backend_hint = default;
    }
                 
        # ---------------------- WORDPRESS SPECIFIC CONFIG -------------------- #
   # Did not cache the RSS feed
   if (req.url ~ "/feed") {
   return (pass);
   }
        # Did not cache the wp-prn login
        if (req.url ~ "/wp-admin") {
        return (pass);
        }
        # Cron Bot
        if (req.url ~ "/bot") {
        return (pass);
        }
   # Blitz hack
   if (req.url ~ "/mu-.*") {
   return (pass);
   }
   # Did not cache the admin and login pages
   if (req.url ~ "/wp-(login|admin)"|| req.url ~ "preview=true" || req.url ~ "xmlrpc.php") {
   return (pass);
   }
   
   # First remove the Google Analytics added parameters, useless for our backend
   if(req.url ~ "(\?|&)(utm_source|utm_medium|utm_campaign|gclid|cx|ie|cof|siteurl)=") {
      set req.url = regsuball(req.url, "&(utm_source|utm_medium|utm_campaign|gclid|cx|ie|cof|siteurl)=([A-z0-9_\-\.%25]+)", "");
      set req.url = regsuball(req.url, "\?(utm_source|utm_medium|utm_campaign|gclid|cx|ie|cof|siteurl)=([A-z0-9_\-\.%25]+)", "?");
      set req.url = regsub(req.url, "\?&", "?");
      set req.url = regsub(req.url, "\?$", "");
   }
   # Remove the "has_js" cookie
   set req.http.Cookie = regsuball(req.http.Cookie, "has_js=[^;]+(; )?", "");
   # Remove any Google Analytics based cookies
   set req.http.Cookie = regsuball(req.http.Cookie, "__utm.=[^;]+(; )?", "");
   # Remove the Quant Capital cookies (added by some plugin, all __qca)
   set req.http.Cookie = regsuball(req.http.Cookie, "__qc.=[^;]+(; )?", "");
   # Remove the wp-settings-1 cookie
   set req.http.Cookie = regsuball(req.http.Cookie, "wp-settings-1=[^;]+(; )?", "");
   # Remove the wp-settings-time-1 cookie
   set req.http.Cookie = regsuball(req.http.Cookie, "wp-settings-time-1=[^;]+(; )?", "");
   # Remove the wp test cookie
   set req.http.Cookie = regsuball(req.http.Cookie, "wordpress_test_cookie=[^;]+(; )?", "");
   # remove cookies for comments cookie to make caching better.
   set req.http.cookie = regsub(req.http.cookie, "dcd9527364a17bb2ae97db0ead3110ed=[^;]+(; )?", "");
   
   # remove ?ver=xxxxx strings from urls so css and js files are cached.
   set req.url = regsub(req.url, "\?ver=.*$", "");
   # Remove "replytocom" from requests to make caching better.
   set req.url = regsub(req.url, "\?replytocom=.*$", "");
   # Strip hash, server doesn't need it.
   set req.url = regsub(req.url, "\#.*$", "");
   # Strip trailing ?
   #set req.url = regsub(req.url, "\?$", "");

   # Are there cookies left with only spaces or that are empty?
   if (req.http.cookie ~ "^ *$") {
   unset req.http.cookie;
   }   
   # Drop any cookies sent to WordPress.
   if (!(req.url ~ "wp-(login|admin)")) {
                       unset req.http.cookie;
        }
        # Cache the following files extensions
   if (req.url ~ "\.(css|js|png|gif|jp(e)?g|swf|ico)") {
   unset req.http.cookie;
   }
   
   # Normalize Accept-Encoding header and compression
   # https://www.varnish-cache.org/docs/3.0/tutorial/vary.html
   if (req.http.Accept-Encoding) {
   # Do no compress compressed files...
   if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg)$") {
   unset req.http.Accept-Encoding;
   } elsif (req.http.Accept-Encoding ~ "gzip") {
   set req.http.Accept-Encoding = "gzip";
   } elsif (req.http.Accept-Encoding ~ "deflate") {
   set req.http.Accept-Encoding = "deflate";
   } else {
   unset req.http.Accept-Encoding;
   }
   }
   
   # Check the cookies for wordpress-specific items
   if (req.http.Cookie ~ "wordpress_" || req.http.Cookie ~ "comment_") {
   return (pass);
   }
   if (!req.http.cookie) {
   unset req.http.cookie;
   }
   # ---------------------- /WORDPRESS SPECIFIC CONFIG -------------------- #
   
   # No cache for big video files
   if (req.url ~ "\.(avi|mp4)") {
      return (pass);
   }   
   
   # Do not cache HTTP authentication and HTTP Cookie
   if (req.http.Authorization || req.http.Cookie) {
   # Not cacheable by default
   return (pass);
   }
   # Cache all others requests
   #return (hash);                     
}

sub vcl_backend_response {
    # Happens after we have read the response headers from the backend.
    #
    # Here you clean the response headers, removing silly Set-Cookie headers
    # and other mistakes your backend does.
   
    # Drop any cookies WordPress tries to send back to the client.
    if (!(bereq.url ~ "wp-(login|admin)")) {
                unset beresp.http.set-cookie;
            }
           
}

sub vcl_deliver {
    # Happens when we have all the pieces we need, and are about to send the
    # response to the client.
    #
    # You can do accounting or modifying the final object here.
   
   if (obj.hits > 0) {
   set resp.http.X-Cache = "cached";
   } else {
   set resp.http.x-Cache = "uncached";
   }

   # Remove some headers
   unset resp.http.X-Powered-By;
   unset resp.http.X-Varnish;
   unset resp.http.Via;
   unset resp.http.Age;
   unset resp.http.Link;
   unset resp.http.Server;
   return (deliver);
}

sub vcl_pipe {
   # Note that only the first request to the backend will have
   # X-Forwarded-For set. If you use X-Forwarded-For and want to
   # have it set for all requests, make sure to have:
   # set bereq.http.connection = "close";
   # here. It is not set by default as it might break some broken web
   # applications, like IIS with NTLM authentication.
   #set bereq.http.Connection = "Close";
   return (pipe);
}

# The data on which the hashing will take place
sub vcl_hash {
   hash_data(req.url);
   if (req.http.host) {
       hash_data(req.http.host);
    } else {
       hash_data(server.ip);
    }
   # hash cookies for requests that have them
    if (req.http.Cookie) {
       hash_data(req.http.Cookie);
    }
 }

sub vcl_hit {
        return (deliver);
}
sub vcl_miss {
        return (fetch);
}
sub vcl_init {
        return (ok);
}
sub vcl_fini {
        return (ok);
}

« Last Edit: July 16, 2017, 05:47:02 PM by blackstar »