Guest User

default.vcl

a guest
Jan 22nd, 2018
110
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. vcl 4.0;
  2.  
  3. backend default {
  4. .host = "127.0.0.1";
  5. .port = "8080";
  6. .first_byte_timeout = 300s;
  7. }
  8.  
  9. acl purge {
  10. "127.0.0.1";
  11. }
  12.  
  13. sub vcl_recv {
  14. if (req.method == "PURGE") {
  15. if (!client.ip ~ purge) {
  16. return(synth(405,"Not allowed."));
  17. }
  18.  
  19. if (req.http.X-Purge-Method == "regex") {
  20. ban("req.url ~ " + req.url + " && req.http.host ~ " + req.http.host);
  21. return (synth(200, "Banned."));
  22. } else {
  23. return (purge);
  24. }
  25. }
  26.  
  27. ### Do not Authorized requests.
  28. if (req.http.Authorization) {
  29. return(pass); // DO NOT CACHE
  30. }
  31.  
  32. ### Pass any requests with the "If-None-Match" header directly.
  33. if (req.http.If-None-Match) {
  34. return(pass); // DO NOT CACHE
  35. }
  36.  
  37. ### Do not cache AJAX requests.
  38. if (req.http.X-Requested-With == "XMLHttpRequest") {
  39. return(pass); // DO NOT CACHE
  40. }
  41.  
  42. ### Only cache GET or HEAD requests. This makes sure the POST (and OPTIONS) requests are always passed.
  43. if (req.method != "GET" && req.method != "HEAD") {
  44. return (pass); // DO NOT CACHE
  45. }
  46.  
  47. ### Static files: Do not cache PDF, XML, ... files (=static & huge and no use caching them - in all Vary: variations!)
  48. if (req.url ~ "\.(doc|mp3|pdf|tif|tiff|xml)(\?.*|)$") {
  49. return(pass); // DO NOT CACHE
  50. }
  51.  
  52. # Unset the header for static files
  53. if (req.url ~ "\.(gif|jpg|jpeg|swf|ttf|css|js|flv|mp3|mp4|pdf|ico|png)(\?.*|)$") {
  54. unset req.http.cookie;
  55. set req.url = regsub(req.url, "\?.*$", "");
  56. }
  57.  
  58. if (req.url ~ "\?(utm_(campaign|medium|source|term)|adParams|client|cx|eid|fbid|feed|ref(id|src)?|v(er|iew))=") {
  59. set req.url = regsub(req.url, "\?.*$", "");
  60. }
  61.  
  62. if (req.url ~ "wp-(login|admin)" || req.url ~ "preview=true" || req.url ~ "xmlrpc.php") {
  63. return (pass);
  64. }
  65.  
  66. if (req.http.cookie) {
  67. # Google Analytics
  68. set req.http.Cookie = regsuball( req.http.Cookie, "(^|;\s*)(__utm[a-z]+)=([^;]*)", "");
  69. set req.http.Cookie = regsuball( req.http.Cookie, "(^|;\s*)(_ga)=([^;]*)", "");
  70.  
  71. # Quant Capital
  72. set req.http.Cookie = regsuball( req.http.Cookie, "(^|;\s*)(__qc[a-z]+)=([^;]*)", "");
  73.  
  74. # __gad __gads
  75. set req.http.Cookie = regsuball( req.http.Cookie, "(^|;\s*)(__gad[a-z]+)=([^;]*)", "");
  76.  
  77. # Google Cookie consent (client javascript cookie)
  78. set req.http.Cookie = regsuball( req.http.Cookie, "(^|;\s*)(displayCookieConsent)=([^;]*)", "");
  79.  
  80. # Other known Cookies: remove them (if found).
  81. set req.http.Cookie = regsuball( req.http.Cookie, "(^|;\s*)(__CT_Data)=([^;]*)", "");
  82. set req.http.Cookie = regsuball( req.http.Cookie, "(^|;\s*)(WRIgnore|WRUID)=([^;]*)", "");
  83.  
  84.  
  85. # PostAction: Remove (once and if found) a ";" prefix followed by 0..n whitespaces.
  86. # INFO \s* = 0..n whitespace characters
  87. set req.http.Cookie = regsub( req.http.Cookie, "^;\s*", "" );
  88.  
  89. # PostAction: Unset the header if it is empty or 0..n whitespaces.
  90. if ( req.http.cookie ~ "^\s*$" ) {
  91. unset req.http.Cookie;
  92. }
  93. }
  94. }
  95.  
  96. sub vcl_backend_response {
  97. if ( (!(bereq.url ~ "(wp-(login|admin)|login)")) || (bereq.method == "GET") ) {
  98. //unset beresp.http.set-cookie;
  99. set beresp.ttl = 1h;
  100. }
  101. # Remove some headers we never want to see
  102. unset beresp.http.Server;
  103. unset beresp.http.X-Powered-By;
  104.  
  105. if (bereq.url ~ "\.(gif|jpg|jpeg|swf|ttf|css|js|flv|mp3|mp4|pdf|ico|png)(\?.*|)$") {
  106. unset beresp.http.cookie;
  107. set beresp.ttl = 365d;
  108. }
  109.  
  110. set beresp.ttl = 10s;
  111. set beresp.grace = 1h;
  112. }
  113.  
  114. sub vcl_deliver {
  115. if (obj.hits > 0) {
  116. set resp.http.X-Cache = "HIT";
  117. } else {
  118. set resp.http.X-Cache = "MISS";
  119. }
  120. set resp.http.Access-Control-Allow-Origin = "*";
  121. set resp.http.Server = "HocVPS Script";
  122. }
  123.  
  124. sub vcl_recv {
  125. # Ask Varnish to fire 750 status for HTTP requests from external IPs and port 80,
  126. # and not from SSL Termination Proxy (Nginx).
  127. if ( (req.http.host ~ "^(?i)www.lytrips.blog" || req.http.host ~ "^(?i)lytrips.blog") && req.http.X-Forwarded-Proto !~ "(?i)https") {
  128. return (synth(750, ""));
  129. }
  130. }
  131.  
  132. sub vcl_synth {
  133. # Listen to 750 status from vcl_recv.
  134. if (resp.status == 750) {
  135. set resp.status = 301;
  136. set resp.http.Location = "https://lytrips.blog" + req.url;
  137. return(deliver);
  138. }
  139. }
RAW Paste Data