Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Service file Exec:
- ExecStart=/usr/sbin/varnishd -j unix,user=vcache -F -a :80 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s file,/var/lib/varnish/varnish_storage.bin,6G -p http_resp_hdr_len=1048576 -t 86400 -p ban_lurker_sleep=0 -p idle_send_timeout=180 -p between_bytes_timeout=180 -p connect_timeout=30 -p http_req_size=2097152 -p http_resp_size=2097152 -p http_req_hdr_len=1048576 -p workspace_client=2097152 -p workspace_backend=2097152 -p gzip_buffer=524288 -p http_max_hdr=256 -p timeout_idle=300 -p timeout_linger=300 -p workspace_session=131072 -p workspace_thread=8192
- #Varnishlog from single refresh of the page:
- * << Request >> 491522
- - Begin req 491521 rxreq
- - Timestamp Start: 1620998164.708614 0.000000 0.000000
- - Timestamp Req: 1620998164.708614 0.000000 0.000000
- - ReqStart 127.0.0.1 46378
- - ReqMethod GET
- - ReqURL /some-url.html
- - ReqProtocol HTTP/1.0
- - ReqHeader X-Real-IP: 127.0.0.1
- - ReqHeader X-Forwarded-For: 127.0.0.1
- - ReqHeader X-Forwarded-Port: 443
- - ReqHeader Host: stage.example.com
- - ReqHeader X-Forwarded-Proto: https
- - ReqHeader X-Forwarded-Host: stage.example.com
- - ReqHeader X-Secure: on
- - ReqHeader Connection: close
- - ReqHeader User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36 Amasty_Fpc
- - ReqHeader Accept: */*
- - ReqHeader Cookie: PHPSESSID=amasty-fpc-crawler;
- - ReqHeader X-Amasty-Crawler-Status: crawl
- - ReqUnset X-Forwarded-For: 127.0.0.1
- - ReqHeader X-Forwarded-For: 127.0.0.1, 127.0.0.1
- - VCL_call RECV
- - ReqHeader grace: none
- - ReqURL /some-url.html
- - ReqURL /some-url.html
- - ReqURL /some-url.html
- - ReqURL /some-url.html
- - ReqUnset Cookie: PHPSESSID=amasty-fpc-crawler;
- - ReqHeader Cookie: PHPSESSID=amasty-fpc-crawler;
- - ReqUnset Cookie: PHPSESSID=amasty-fpc-crawler;
- - ReqHeader Cookie: PHPSESSID=amasty-fpc-crawler;
- - VCL_return hash
- - VCL_call HASH
- - VCL_return lookup
- - ExpBan 3 banned lookup
- - VCL_call MISS
- - ReqHeader x-cache: miss
- - VCL_return fetch
- - Link bereq 491523 fetch
- - Timestamp Fetch: 1620998239.068560 74.359946 74.359946
- - RespProtocol HTTP/1.1
- - RespStatus 200
- - RespReason OK
- - RespHeader Date: Fri, 14 May 2021 13:16:05 GMT
- - RespHeader Server: Apache/2.4.29 (Ubuntu)
- - RespHeader Cache-Control: max-age=31536000, must-revalidate
- - RespHeader Pragma: cache
- - RespHeader X-Magento-Tags: store,cms_b,cat_p_659571,cat_p,cat_c_167,cat_p_642827,cat_p_661696,cat_p_411957,cat_p_661698,cat_p_427250,cat_p_643424,cat_p_546338,cat_p_621599,cat_p_663589,cat_p_207664,cat_p_624146,cat_p_265860,cat_p_654792,cat_p_655508,cat_p_660280,ca
- - RespHeader X-Content-Type-Options: nosniff
- - RespHeader X-XSS-Protection: 1; mode=block
- - RespHeader X-Frame-Options: SAMEORIGIN
- - RespHeader X-UA-Compatible: IE=edge
- - RespHeader Content-Type: text/html; charset=UTF-8
- - RespHeader Content-Encoding: gzip
- - RespHeader Vary: Accept-Encoding
- - RespHeader X-Varnish: 491522
- - RespHeader Age: 0
- - RespHeader Via: 1.1 varnish (Varnish/5.2)
- - VCL_call DELIVER
- - ReqUnset x-cache: miss
- - ReqHeader x-cache: miss cached
- - RespHeader x-cache: miss cached
- - RespUnset Age: 0
- - RespUnset Pragma: cache
- - RespHeader Pragma: no-cache
- - RespHeader Expires: -1
- - RespUnset Cache-Control: max-age=31536000, must-revalidate
- - RespHeader Cache-Control: no-store, no-cache, must-revalidate, max-age=0
- - RespUnset X-Magento-Tags: store,cms_b,cat_p_659571,cat_p,cat_c_167,cat_p_642827,cat_p_661696,cat_p_411957,cat_p_661698,cat_p_427250,cat_p_643424,cat_p_546338,cat_p_621599,cat_p_663589,cat_p_207664,cat_p_624146,cat_p_265860,cat_p_654792,cat_p_655508,cat_p_660280,ca
- - RespUnset Server: Apache/2.4.29 (Ubuntu)
- - RespUnset X-Varnish: 491522
- - RespUnset Via: 1.1 varnish (Varnish/5.2)
- - VCL_return deliver
- - Timestamp Process: 1620998239.068615 74.360001 0.000055
- - RespUnset Content-Encoding: gzip
- - RespHeader Accept-Ranges: bytes
- - RespHeader Connection: close
- - Debug "Hit idle send timeout, wrote = 32768/524685; retrying"
- - Debug "Write error, retval = -1, len = 491917, errno = Broken pipe"
- - Gzip U D - 39784 524288 80 0 0
- - Timestamp Resp: 1620998239.070724 74.362109 0.002108
- - ReqAcct 473 0 473 397 524288 524685
- - End
- * << Request >> 688130
- - Begin req 688129 rxreq
- - Timestamp Start: 1620998171.625723 0.000000 0.000000
- - Timestamp Req: 1620998171.625723 0.000000 0.000000
- - ReqStart 127.0.0.1 46430
- - ReqMethod GET
- - ReqURL /some-url.html
- - ReqProtocol HTTP/1.0
- - ReqHeader X-Real-IP: x.x.x.x
- - ReqHeader X-Forwarded-For: x.x.x.x
- - ReqHeader X-Forwarded-Port: 443
- - ReqHeader Host: stage.example.com
- - ReqHeader X-Forwarded-Proto: https
- - ReqHeader X-Forwarded-Host: stage.example.com
- - ReqHeader X-Secure: on
- - ReqHeader Connection: close
- - ReqHeader cache-control: max-age=0
- - ReqHeader sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="90", "Google Chrome";v="90"
- - ReqHeader sec-ch-ua-mobile: ?0
- - ReqHeader upgrade-insecure-requests: 1
- - ReqHeader user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36
- - ReqHeader accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
- - ReqHeader sec-fetch-site: none
- - ReqHeader sec-fetch-mode: navigate
- - ReqHeader sec-fetch-user: ?1
- - ReqHeader sec-fetch-dest: document
- - ReqHeader accept-encoding: gzip, deflate, br
- - ReqHeader accept-language: en-US,en;q=0.9
- - ReqHeader cookie: _ga=GA1.2.1323021052.1609531981; __insp_uid=2634399250; tracker_device=c46d6fea-50c2-4fd7-ab45-e9b54dd6f877; _clck=9ao6q9; __insp_wid=947107993; __insp_nv=false; __insp_targlpt=NDA0IC4uLiBmZWVscyBzbyBlbXB0eSBoZXJlIHwgcm9vbSBzZXJ2aWNlIDM2MMKw; __i
- - ReqUnset X-Forwarded-For: x.x.x.x
- - ReqHeader X-Forwarded-For: x.x.x.x, 127.0.0.1
- - VCL_call RECV
- - ReqHeader grace: none
- - ReqURL /some-url.html
- - ReqUnset accept-encoding: gzip, deflate, br
- - ReqHeader Accept-Encoding: gzip
- - ReqURL /some-url.html
- - ReqURL /some-url.html
- - ReqURL /some-url.html
- - ReqUnset cookie: _ga=GA1.2.1323021052.1609531981; __insp_uid=2634399250; tracker_device=c46d6fea-50c2-4fd7-ab45-e9b54dd6f877; _clck=9ao6q9; __insp_wid=947107993; __insp_nv=false; __insp_targlpt=NDA0IC4uLiBmZWVscyBzbyBlbXB0eSBoZXJlIHwgcm9vbSBzZXJ2aWNlIDM2MMKw; __i
- - ReqHeader Cookie: ; tracker_device=c46d6fea-50c2-4fd7-ab45-e9b54dd6f877; form_key=VLFxwracTAyqwixq; mage-cache-storage=%7B%7D; mage-cache-storage-section-invalidation=%7B%7D; maghos_product_view=1; PHPSESSID=ll3r5949f667k0dlf4do86sris; form_key=VLFxwracTAyqwixq; m
- - ReqUnset Cookie: ; tracker_device=c46d6fea-50c2-4fd7-ab45-e9b54dd6f877; form_key=VLFxwracTAyqwixq; mage-cache-storage=%7B%7D; mage-cache-storage-section-invalidation=%7B%7D; maghos_product_view=1; PHPSESSID=ll3r5949f667k0dlf4do86sris; form_key=VLFxwracTAyqwixq; m
- - ReqHeader Cookie: tracker_device=c46d6fea-50c2-4fd7-ab45-e9b54dd6f877; form_key=VLFxwracTAyqwixq; mage-cache-storage=%7B%7D; mage-cache-storage-section-invalidation=%7B%7D; maghos_product_view=1; PHPSESSID=ll3r5949f667k0dlf4do86sris; form_key=VLFxwracTAyqwixq; mag
- - VCL_return hash
- - VCL_call HASH
- - VCL_return lookup
- - Timestamp Waitinglist: 1620998239.070892 67.445169 67.445169
- - Hit 491523 86467.407670 10.000000 0.000000
- - VCL_call HIT
- - ReqHeader x-cache: hit
- - VCL_return deliver
- - RespProtocol HTTP/1.1
- - RespStatus 200
- - RespReason OK
- - RespHeader Date: Fri, 14 May 2021 13:16:05 GMT
- - RespHeader Server: Apache/2.4.29 (Ubuntu)
- - RespHeader Cache-Control: max-age=31536000, must-revalidate
- - RespHeader Pragma: cache
- - RespHeader X-Magento-Tags: store,cms_b,cat_p_659571,cat_p,cat_c_167,cat_p_642827,cat_p_661696,cat_p_411957,cat_p_661698,cat_p_427250,cat_p_643424,cat_p_546338,cat_p_621599,cat_p_663589,cat_p_207664,cat_p_624146,cat_p_265860,cat_p_654792,cat_p_655508,cat_p_660280,ca
- - RespHeader X-Content-Type-Options: nosniff
- - RespHeader X-XSS-Protection: 1; mode=block
- - RespHeader X-Frame-Options: SAMEORIGIN
- - RespHeader X-UA-Compatible: IE=edge
- - RespHeader Content-Type: text/html; charset=UTF-8
- - RespHeader Content-Encoding: gzip
- - RespHeader Vary: Accept-Encoding
- - RespHeader X-Varnish: 688130 491523
- - RespHeader Age: 0
- - RespHeader Via: 1.1 varnish (Varnish/5.2)
- - VCL_call DELIVER
- - ReqUnset x-cache: hit
- - ReqHeader x-cache: hit cached
- - RespHeader x-cache: hit cached
- - RespUnset Age: 0
- - RespUnset Pragma: cache
- - RespHeader Pragma: no-cache
- - RespHeader Expires: -1
- - RespUnset Cache-Control: max-age=31536000, must-revalidate
- - RespHeader Cache-Control: no-store, no-cache, must-revalidate, max-age=0
- - RespUnset X-Magento-Tags: store,cms_b,cat_p_659571,cat_p,cat_c_167,cat_p_642827,cat_p_661696,cat_p_411957,cat_p_661698,cat_p_427250,cat_p_643424,cat_p_546338,cat_p_621599,cat_p_663589,cat_p_207664,cat_p_624146,cat_p_265860,cat_p_654792,cat_p_655508,cat_p_660280,ca
- - RespUnset Server: Apache/2.4.29 (Ubuntu)
- - RespUnset X-Varnish: 688130 491523
- - RespUnset Via: 1.1 varnish (Varnish/5.2)
- - VCL_return deliver
- - Timestamp Process: 1620998239.070988 67.445265 0.000096
- - RespHeader Accept-Ranges: bytes
- - RespHeader Content-Length: 58294
- - RespHeader Connection: close
- - Timestamp Resp: 1620998239.071090 67.445367 0.000102
- - ReqAcct 1776 0 1776 443 58294 58737
- - End
- #VCL - Excuse the mess. It was pieced together as issues arose and since it works, was just left alone.
- # VCL version 5.0 is not supported so it should be 4.0 even though actually used Varnish version is 5
- vcl 4.0;
- sub vcl_recv {
- unset req.http.x-cache;
- #testing https redirect
- #if ( (req.http.host ~ "^(?i)beta2.example.com" || req.http.host ~ "^(?i)example.com" || req.http.host ~ "^(?i)www.example.com") && req.http.X-Forwarded-Proto !~ "(?i)https") {
- if ( (req.http.host ~ "^(?i)stage.example.com") && req.http.X-Forwarded-Proto !~ "(?i)https") {
- return (synth(750, ""));
- }
- #end https redirect testing
- }
- sub vcl_hit {
- set req.http.x-cache = "hit";
- }
- sub vcl_miss {
- set req.http.x-cache = "miss";
- }
- sub vcl_pass {
- set req.http.x-cache = "pass";
- }
- sub vcl_pipe {
- set req.http.x-cache = "pipe uncacheable";
- }
- sub vcl_synth {
- set resp.http.x-cache = "synth synth";
- if (resp.status == 750) {
- set resp.status = 301;
- set resp.http.Location = "https://stage.example.com" + req.url;
- return(deliver);
- }
- }
- sub vcl_deliver {
- if (obj.uncacheable) {
- set req.http.x-cache = req.http.x-cache + " uncacheable" ;
- } else {
- set req.http.x-cache = req.http.x-cache + " cached" ;
- }
- # uncomment the following line to show the information in the response
- set resp.http.x-cache = req.http.x-cache;
- }
- import std;
- # The minimal Varnish version is 5.0
- # For SSL offloading, pass the following header in your proxy server or load balancer: 'SSL-OFFLOADED: https'
- backend default {
- # .host = "localhost";
- .host = "127.0.0.1";
- .port = "8080";
- .first_byte_timeout = 3600s;
- .between_bytes_timeout = 180s;
- # .probe = {
- # .url = "/pub/health_check.php";
- # .timeout = 2s;
- # .interval = 5s;
- # .window = 10;
- # .threshold = 5;
- # }
- }
- acl purge {
- "localhost";
- }
- sub vcl_recv {
- if (req.method == "PURGE") {
- if (client.ip !~ purge) {
- return (synth(405, "Method not allowed"));
- }
- # To use the X-Pool header for purging varnish during automated deployments, make sure the X-Pool header
- # has been added to the response in your backend server config. This is used, for example, by the
- # capistrano-magento2 gem for purging old content from varnish during it's deploy routine.
- if (!req.http.X-Magento-Tags-Pattern && !req.http.X-Pool) {
- return (synth(400, "X-Magento-Tags-Pattern or X-Pool header required"));
- }
- if (req.http.X-Magento-Tags-Pattern) {
- ban("obj.http.X-Magento-Tags ~ " + req.http.X-Magento-Tags-Pattern);
- }
- if (req.http.X-Pool) {
- ban("obj.http.X-Pool ~ " + req.http.X-Pool);
- }
- #Added to test removing Varnish "Error" page on successful purge
- ban("obj.http.X-Magento-Tags ~ " + req.http.X-Magento-Tags-Pattern);
- #End
- return (synth(200, "Purged"));
- }
- if (req.url == "/sitemap.xml") {
- return(pass);
- }
- if (req.method != "GET" &&
- req.method != "HEAD" &&
- req.method != "PUT" &&
- req.method != "POST" &&
- req.method != "TRACE" &&
- req.method != "OPTIONS" &&
- req.method != "DELETE") {
- /* Non-RFC2616 or CONNECT which is weird. */
- return (pipe);
- }
- # We only deal with GET and HEAD by default
- if (req.method != "GET" && req.method != "HEAD") {
- return (pass);
- }
- # Bypass shopping cart, checkout and search requests
- if (req.url ~ "/checkout" || req.url ~ "/catalogsearch" || req.url ~ "/customer/account" || req.url ~ "/customer/address" || req.url ~ "/newsletter/manage" || req.url ~ "/sales/order/history" || req.url ~ "/wishlist" || req.url ~ "/review/customer" || req.url ~ "/admin_xxxxxx" || req.url ~ "/rest") {
- return (pass);
- }
- # Bypass health check requests
- if (req.url ~ "/pub/health_check.php") {
- return (pass);
- }
- # Set initial grace period usage status
- set req.http.grace = "none";
- # normalize url in case of leading HTTP scheme and domain
- set req.url = regsub(req.url, "^http[s]?://", "");
- # collect all cookies
- std.collect(req.http.Cookie);
- # Compression filter. See https://www.varnish-cache.org/trac/wiki/FAQ/Compression
- if (req.http.Accept-Encoding) {
- if (req.url ~ "\.(jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf|flv)$") {
- # No point in compressing these
- unset req.http.Accept-Encoding;
- } elsif (req.http.Accept-Encoding ~ "gzip") {
- set req.http.Accept-Encoding = "gzip";
- } elsif (req.http.Accept-Encoding ~ "deflate" && req.http.user-agent !~ "MSIE") {
- set req.http.Accept-Encoding = "deflate";
- } else {
- # unkown algorithm
- unset req.http.Accept-Encoding;
- }
- }
- # Remove Google gclid parameters to minimize the cache objects
- set req.url = regsuball(req.url,"\?gclid=[^&]+$",""); # strips when QS = "?gclid=AAA"
- set req.url = regsuball(req.url,"\?gclid=[^&]+&","?"); # strips when QS = "?gclid=AAA&foo=bar"
- set req.url = regsuball(req.url,"&gclid=[^&]+",""); # strips when QS = "?foo=bar&gclid=AAA" or QS = "?foo=bar&gclid=AAA&bar=baz"
- # Remove has_js and Cloudflare/Google Analytics __* cookies.
- set req.http.Cookie = regsuball(req.http.Cookie, "(^|;\s*)(_[_a-z]+|has_js)=[^;]*", "");
- # Remove a ";" prefix, if present.
- set req.http.Cookie = regsub(req.http.Cookie, "^;\s*", "");
- #Start strip te mailchimp crap in URLs
- if (req.url ~ "(\?|&)(gclid|cx|ie|cof|siteurl|zanpid|origin|mc_[a-z]+|utm_[a-z]+)=") {
- set req.url = regsuball(req.url, "(gclid|cx|ie|cof|siteurl|zanpid|origin|mc_[a-z]+|utm_[a-z]+)=[-_A-z0-9+()%.]+&?", "");
- set req.url = regsub(req.url, "[?|&]+$", "");
- }
- #End strip the mailchimp crap in URLs
- # Static files caching
- if (req.url ~ "^/(pub/)?(media|static)/") {
- # Static files should not be cached by default
- #return (pass);
- # But if you use a few locales and don't use CDN you can enable caching static files by commenting previous line (#return (pass);) and uncommenting next 3 lines
- unset req.http.Https;
- unset req.http.SSL-OFFLOADED;
- unset req.http.Cookie;
- }
- return (hash);
- }
- sub vcl_hash {
- if (req.http.cookie ~ "X-Magento-Vary=") {
- hash_data(regsub(req.http.cookie, "^.*?X-Magento-Vary=([^;]+);*.*$", "\1"));
- }
- # For multi site configurations to not cache each other's content
- if (req.http.host) {
- hash_data(req.http.host);
- } else {
- hash_data(server.ip);
- }
- # To make sure http users don't see ssl warning
- if (req.http.SSL-OFFLOADED) {
- hash_data(req.http.SSL-OFFLOADED);
- }
- }
- sub vcl_backend_response {
- #Disabed on stage for testing
- # set beresp.grace = 3d;
- if (beresp.http.content-type ~ "text") {
- set beresp.do_esi = true;
- }
- if (bereq.url ~ "\.js$" || beresp.http.content-type ~ "text") {
- set beresp.do_gzip = true;
- }
- if (beresp.http.X-Magento-Debug) {
- set beresp.http.X-Magento-Cache-Control = beresp.http.Cache-Control;
- }
- # cache only successfully responses and 404s
- # if (beresp.status != 200 && beresp.status != 404) {
- if (beresp.status != 200) {
- set beresp.ttl = 0s;
- set beresp.uncacheable = true;
- return (deliver);
- } elsif (beresp.http.Cache-Control ~ "private") {
- set beresp.uncacheable = true;
- set beresp.ttl = 8640000s;
- return (deliver);
- }
- # validate if we need to cache it and prevent from setting cookie
- # images, css and js are cacheable by default so we have to remove cookie also
- if (beresp.ttl > 0s && (bereq.method == "GET" || bereq.method == "HEAD")) {
- unset beresp.http.set-cookie;
- unset beresp.http.expires;
- set beresp.ttl = 86400s;
- }
- # If page is not cacheable then bypass varnish for 2 minutes as Hit-For-Pass
- if (beresp.ttl <= 0s ||
- beresp.http.Surrogate-control ~ "no-store" ||
- (!beresp.http.Surrogate-Control &&
- beresp.http.Cache-Control ~ "no-cache|no-store") ||
- beresp.http.Vary == "*") {
- # Mark as Hit-For-Pass for the next 2 minutes
- set beresp.ttl = 120s;
- set beresp.uncacheable = true;
- }
- }
- sub vcl_deliver {
- if (resp.http.X-Magento-Debug) {
- if (resp.http.x-varnish ~ " ") {
- set resp.http.X-Magento-Cache-Debug = "HIT";
- set resp.http.Grace = req.http.grace;
- } else {
- set resp.http.X-Magento-Cache-Debug = "MISS";
- }
- } else {
- unset resp.http.Age;
- }
- # Not letting browser to cache non-static files.
- if (resp.http.Cache-Control !~ "private" && req.url !~ "^/(pub/)?(media|static)/") {
- set resp.http.Pragma = "no-cache";
- set resp.http.Expires = "-1";
- set resp.http.Cache-Control = "no-store, no-cache, must-revalidate, max-age=0";
- }
- unset resp.http.X-Magento-Debug;
- unset resp.http.X-Magento-Tags;
- unset resp.http.X-Powered-By;
- unset resp.http.Server;
- unset resp.http.X-Varnish;
- unset resp.http.Via;
- unset resp.http.Link;
- }
- sub vcl_hit {
- if (obj.ttl >= 0s) {
- # Hit within TTL period
- return (deliver);
- }
- if (std.healthy(req.backend_hint)) {
- if (obj.ttl + 300s > 0s) {
- # Hit after TTL expiration, but within grace period
- set req.http.grace = "normal (healthy server)";
- return (deliver);
- } else {
- # Hit after TTL and grace expiration
- return (miss);
- }
- } else {
- # server is not healthy, retrieve from cache
- set req.http.grace = "unlimited (unhealthy server)";
- return (deliver);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement