Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vcl 4.0;
- backend default {
- .host = "127.0.0.1";
- .port = "8080";
- .first_byte_timeout = 300s;
- }
- acl purge {
- "127.0.0.1";
- }
- sub vcl_recv {
- if (req.method == "PURGE") {
- if (!client.ip ~ purge) {
- return(synth(405,"Not allowed."));
- }
- if (req.http.X-Purge-Method == "regex") {
- ban("req.url ~ " + req.url + " && req.http.host ~ " + req.http.host);
- return (synth(200, "Banned."));
- } else {
- return (purge);
- }
- }
- ### Do not Authorized requests.
- if (req.http.Authorization) {
- return(pass); // DO NOT CACHE
- }
- ### Pass any requests with the "If-None-Match" header directly.
- if (req.http.If-None-Match) {
- return(pass); // DO NOT CACHE
- }
- ### Do not cache AJAX requests.
- if (req.http.X-Requested-With == "XMLHttpRequest") {
- return(pass); // DO NOT CACHE
- }
- ### Only cache GET or HEAD requests. This makes sure the POST (and OPTIONS) requests are always passed.
- if (req.method != "GET" && req.method != "HEAD") {
- return (pass); // DO NOT CACHE
- }
- ### Static files: Do not cache PDF, XML, ... files (=static & huge and no use caching them - in all Vary: variations!)
- if (req.url ~ "\.(doc|mp3|pdf|tif|tiff|xml)(\?.*|)$") {
- return(pass); // DO NOT CACHE
- }
- # Unset the header for static files
- if (req.url ~ "\.(gif|jpg|jpeg|swf|ttf|css|js|flv|mp3|mp4|pdf|ico|png)(\?.*|)$") {
- unset req.http.cookie;
- set req.url = regsub(req.url, "\?.*$", "");
- }
- if (req.url ~ "\?(utm_(campaign|medium|source|term)|adParams|client|cx|eid|fbid|feed|ref(id|src)?|v(er|iew))=") {
- set req.url = regsub(req.url, "\?.*$", "");
- }
- if (req.url ~ "wp-(login|admin)" || req.url ~ "preview=true" || req.url ~ "xmlrpc.php") {
- return (pass);
- }
- if (req.http.cookie) {
- # Google Analytics
- set req.http.Cookie = regsuball( req.http.Cookie, "(^|;\s*)(__utm[a-z]+)=([^;]*)", "");
- set req.http.Cookie = regsuball( req.http.Cookie, "(^|;\s*)(_ga)=([^;]*)", "");
- # Quant Capital
- set req.http.Cookie = regsuball( req.http.Cookie, "(^|;\s*)(__qc[a-z]+)=([^;]*)", "");
- # __gad __gads
- set req.http.Cookie = regsuball( req.http.Cookie, "(^|;\s*)(__gad[a-z]+)=([^;]*)", "");
- # Google Cookie consent (client javascript cookie)
- set req.http.Cookie = regsuball( req.http.Cookie, "(^|;\s*)(displayCookieConsent)=([^;]*)", "");
- # Other known Cookies: remove them (if found).
- set req.http.Cookie = regsuball( req.http.Cookie, "(^|;\s*)(__CT_Data)=([^;]*)", "");
- set req.http.Cookie = regsuball( req.http.Cookie, "(^|;\s*)(WRIgnore|WRUID)=([^;]*)", "");
- # PostAction: Remove (once and if found) a ";" prefix followed by 0..n whitespaces.
- # INFO \s* = 0..n whitespace characters
- set req.http.Cookie = regsub( req.http.Cookie, "^;\s*", "" );
- # PostAction: Unset the header if it is empty or 0..n whitespaces.
- if ( req.http.cookie ~ "^\s*$" ) {
- unset req.http.Cookie;
- }
- }
- }
- sub vcl_backend_response {
- if ( (!(bereq.url ~ "(wp-(login|admin)|login)")) || (bereq.method == "GET") ) {
- //unset beresp.http.set-cookie;
- set beresp.ttl = 1h;
- }
- # Remove some headers we never want to see
- unset beresp.http.Server;
- unset beresp.http.X-Powered-By;
- if (bereq.url ~ "\.(gif|jpg|jpeg|swf|ttf|css|js|flv|mp3|mp4|pdf|ico|png)(\?.*|)$") {
- unset beresp.http.cookie;
- set beresp.ttl = 365d;
- }
- set beresp.ttl = 10s;
- set beresp.grace = 1h;
- }
- sub vcl_deliver {
- if (obj.hits > 0) {
- set resp.http.X-Cache = "HIT";
- } else {
- set resp.http.X-Cache = "MISS";
- }
- set resp.http.Access-Control-Allow-Origin = "*";
- set resp.http.Server = "HocVPS Script";
- }
- sub vcl_recv {
- # Ask Varnish to fire 750 status for HTTP requests from external IPs and port 80,
- # and not from SSL Termination Proxy (Nginx).
- if ( (req.http.host ~ "^(?i)www.lytrips.blog" || req.http.host ~ "^(?i)lytrips.blog") && req.http.X-Forwarded-Proto !~ "(?i)https") {
- return (synth(750, ""));
- }
- }
- sub vcl_synth {
- # Listen to 750 status from vcl_recv.
- if (resp.status == 750) {
- set resp.status = 301;
- set resp.http.Location = "https://lytrips.blog" + req.url;
- return(deliver);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement