Advertisement
Guest User

Untitled

a guest
May 14th, 2021
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.37 KB | None | 0 0
  1. #Service file Exec:
  2.  
  3. 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
  4.  
  5.  
  6.  
  7. #Varnishlog from single refresh of the page:
  8.  
  9. * << Request >> 491522
  10. - Begin req 491521 rxreq
  11. - Timestamp Start: 1620998164.708614 0.000000 0.000000
  12. - Timestamp Req: 1620998164.708614 0.000000 0.000000
  13. - ReqStart 127.0.0.1 46378
  14. - ReqMethod GET
  15. - ReqURL /some-url.html
  16. - ReqProtocol HTTP/1.0
  17. - ReqHeader X-Real-IP: 127.0.0.1
  18. - ReqHeader X-Forwarded-For: 127.0.0.1
  19. - ReqHeader X-Forwarded-Port: 443
  20. - ReqHeader Host: stage.example.com
  21. - ReqHeader X-Forwarded-Proto: https
  22. - ReqHeader X-Forwarded-Host: stage.example.com
  23. - ReqHeader X-Secure: on
  24. - ReqHeader Connection: close
  25. - 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
  26. - ReqHeader Accept: */*
  27. - ReqHeader Cookie: PHPSESSID=amasty-fpc-crawler;
  28. - ReqHeader X-Amasty-Crawler-Status: crawl
  29. - ReqUnset X-Forwarded-For: 127.0.0.1
  30. - ReqHeader X-Forwarded-For: 127.0.0.1, 127.0.0.1
  31. - VCL_call RECV
  32. - ReqHeader grace: none
  33. - ReqURL /some-url.html
  34. - ReqURL /some-url.html
  35. - ReqURL /some-url.html
  36. - ReqURL /some-url.html
  37. - ReqUnset Cookie: PHPSESSID=amasty-fpc-crawler;
  38. - ReqHeader Cookie: PHPSESSID=amasty-fpc-crawler;
  39. - ReqUnset Cookie: PHPSESSID=amasty-fpc-crawler;
  40. - ReqHeader Cookie: PHPSESSID=amasty-fpc-crawler;
  41. - VCL_return hash
  42. - VCL_call HASH
  43. - VCL_return lookup
  44. - ExpBan 3 banned lookup
  45. - VCL_call MISS
  46. - ReqHeader x-cache: miss
  47. - VCL_return fetch
  48. - Link bereq 491523 fetch
  49. - Timestamp Fetch: 1620998239.068560 74.359946 74.359946
  50. - RespProtocol HTTP/1.1
  51. - RespStatus 200
  52. - RespReason OK
  53. - RespHeader Date: Fri, 14 May 2021 13:16:05 GMT
  54. - RespHeader Server: Apache/2.4.29 (Ubuntu)
  55. - RespHeader Cache-Control: max-age=31536000, must-revalidate
  56. - RespHeader Pragma: cache
  57. - 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
  58. - RespHeader X-Content-Type-Options: nosniff
  59. - RespHeader X-XSS-Protection: 1; mode=block
  60. - RespHeader X-Frame-Options: SAMEORIGIN
  61. - RespHeader X-UA-Compatible: IE=edge
  62. - RespHeader Content-Type: text/html; charset=UTF-8
  63. - RespHeader Content-Encoding: gzip
  64. - RespHeader Vary: Accept-Encoding
  65. - RespHeader X-Varnish: 491522
  66. - RespHeader Age: 0
  67. - RespHeader Via: 1.1 varnish (Varnish/5.2)
  68. - VCL_call DELIVER
  69. - ReqUnset x-cache: miss
  70. - ReqHeader x-cache: miss cached
  71. - RespHeader x-cache: miss cached
  72. - RespUnset Age: 0
  73. - RespUnset Pragma: cache
  74. - RespHeader Pragma: no-cache
  75. - RespHeader Expires: -1
  76. - RespUnset Cache-Control: max-age=31536000, must-revalidate
  77. - RespHeader Cache-Control: no-store, no-cache, must-revalidate, max-age=0
  78. - 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
  79. - RespUnset Server: Apache/2.4.29 (Ubuntu)
  80. - RespUnset X-Varnish: 491522
  81. - RespUnset Via: 1.1 varnish (Varnish/5.2)
  82. - VCL_return deliver
  83. - Timestamp Process: 1620998239.068615 74.360001 0.000055
  84. - RespUnset Content-Encoding: gzip
  85. - RespHeader Accept-Ranges: bytes
  86. - RespHeader Connection: close
  87. - Debug "Hit idle send timeout, wrote = 32768/524685; retrying"
  88. - Debug "Write error, retval = -1, len = 491917, errno = Broken pipe"
  89. - Gzip U D - 39784 524288 80 0 0
  90. - Timestamp Resp: 1620998239.070724 74.362109 0.002108
  91. - ReqAcct 473 0 473 397 524288 524685
  92. - End
  93.  
  94. * << Request >> 688130
  95. - Begin req 688129 rxreq
  96. - Timestamp Start: 1620998171.625723 0.000000 0.000000
  97. - Timestamp Req: 1620998171.625723 0.000000 0.000000
  98. - ReqStart 127.0.0.1 46430
  99. - ReqMethod GET
  100. - ReqURL /some-url.html
  101. - ReqProtocol HTTP/1.0
  102. - ReqHeader X-Real-IP: x.x.x.x
  103. - ReqHeader X-Forwarded-For: x.x.x.x
  104. - ReqHeader X-Forwarded-Port: 443
  105. - ReqHeader Host: stage.example.com
  106. - ReqHeader X-Forwarded-Proto: https
  107. - ReqHeader X-Forwarded-Host: stage.example.com
  108. - ReqHeader X-Secure: on
  109. - ReqHeader Connection: close
  110. - ReqHeader cache-control: max-age=0
  111. - ReqHeader sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="90", "Google Chrome";v="90"
  112. - ReqHeader sec-ch-ua-mobile: ?0
  113. - ReqHeader upgrade-insecure-requests: 1
  114. - 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
  115. - 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
  116. - ReqHeader sec-fetch-site: none
  117. - ReqHeader sec-fetch-mode: navigate
  118. - ReqHeader sec-fetch-user: ?1
  119. - ReqHeader sec-fetch-dest: document
  120. - ReqHeader accept-encoding: gzip, deflate, br
  121. - ReqHeader accept-language: en-US,en;q=0.9
  122. - 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
  123. - ReqUnset X-Forwarded-For: x.x.x.x
  124. - ReqHeader X-Forwarded-For: x.x.x.x, 127.0.0.1
  125. - VCL_call RECV
  126. - ReqHeader grace: none
  127. - ReqURL /some-url.html
  128. - ReqUnset accept-encoding: gzip, deflate, br
  129. - ReqHeader Accept-Encoding: gzip
  130. - ReqURL /some-url.html
  131. - ReqURL /some-url.html
  132. - ReqURL /some-url.html
  133. - 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
  134. - 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
  135. - 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
  136. - 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
  137. - VCL_return hash
  138. - VCL_call HASH
  139. - VCL_return lookup
  140. - Timestamp Waitinglist: 1620998239.070892 67.445169 67.445169
  141. - Hit 491523 86467.407670 10.000000 0.000000
  142. - VCL_call HIT
  143. - ReqHeader x-cache: hit
  144. - VCL_return deliver
  145. - RespProtocol HTTP/1.1
  146. - RespStatus 200
  147. - RespReason OK
  148. - RespHeader Date: Fri, 14 May 2021 13:16:05 GMT
  149. - RespHeader Server: Apache/2.4.29 (Ubuntu)
  150. - RespHeader Cache-Control: max-age=31536000, must-revalidate
  151. - RespHeader Pragma: cache
  152. - 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
  153. - RespHeader X-Content-Type-Options: nosniff
  154. - RespHeader X-XSS-Protection: 1; mode=block
  155. - RespHeader X-Frame-Options: SAMEORIGIN
  156. - RespHeader X-UA-Compatible: IE=edge
  157. - RespHeader Content-Type: text/html; charset=UTF-8
  158. - RespHeader Content-Encoding: gzip
  159. - RespHeader Vary: Accept-Encoding
  160. - RespHeader X-Varnish: 688130 491523
  161. - RespHeader Age: 0
  162. - RespHeader Via: 1.1 varnish (Varnish/5.2)
  163. - VCL_call DELIVER
  164. - ReqUnset x-cache: hit
  165. - ReqHeader x-cache: hit cached
  166. - RespHeader x-cache: hit cached
  167. - RespUnset Age: 0
  168. - RespUnset Pragma: cache
  169. - RespHeader Pragma: no-cache
  170. - RespHeader Expires: -1
  171. - RespUnset Cache-Control: max-age=31536000, must-revalidate
  172. - RespHeader Cache-Control: no-store, no-cache, must-revalidate, max-age=0
  173. - 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
  174. - RespUnset Server: Apache/2.4.29 (Ubuntu)
  175. - RespUnset X-Varnish: 688130 491523
  176. - RespUnset Via: 1.1 varnish (Varnish/5.2)
  177. - VCL_return deliver
  178. - Timestamp Process: 1620998239.070988 67.445265 0.000096
  179. - RespHeader Accept-Ranges: bytes
  180. - RespHeader Content-Length: 58294
  181. - RespHeader Connection: close
  182. - Timestamp Resp: 1620998239.071090 67.445367 0.000102
  183. - ReqAcct 1776 0 1776 443 58294 58737
  184. - End
  185.  
  186.  
  187.  
  188. #VCL - Excuse the mess. It was pieced together as issues arose and since it works, was just left alone.
  189.  
  190. # VCL version 5.0 is not supported so it should be 4.0 even though actually used Varnish version is 5
  191. vcl 4.0;
  192.  
  193. sub vcl_recv {
  194. unset req.http.x-cache;
  195. #testing https redirect
  196. #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") {
  197. if ( (req.http.host ~ "^(?i)stage.example.com") && req.http.X-Forwarded-Proto !~ "(?i)https") {
  198. return (synth(750, ""));
  199. }
  200. #end https redirect testing
  201. }
  202.  
  203. sub vcl_hit {
  204. set req.http.x-cache = "hit";
  205. }
  206.  
  207. sub vcl_miss {
  208. set req.http.x-cache = "miss";
  209. }
  210.  
  211. sub vcl_pass {
  212. set req.http.x-cache = "pass";
  213. }
  214.  
  215. sub vcl_pipe {
  216. set req.http.x-cache = "pipe uncacheable";
  217. }
  218.  
  219. sub vcl_synth {
  220. set resp.http.x-cache = "synth synth";
  221. if (resp.status == 750) {
  222. set resp.status = 301;
  223. set resp.http.Location = "https://stage.example.com" + req.url;
  224. return(deliver);
  225. }
  226. }
  227.  
  228. sub vcl_deliver {
  229. if (obj.uncacheable) {
  230. set req.http.x-cache = req.http.x-cache + " uncacheable" ;
  231. } else {
  232. set req.http.x-cache = req.http.x-cache + " cached" ;
  233. }
  234. # uncomment the following line to show the information in the response
  235. set resp.http.x-cache = req.http.x-cache;
  236. }
  237.  
  238. import std;
  239. # The minimal Varnish version is 5.0
  240. # For SSL offloading, pass the following header in your proxy server or load balancer: 'SSL-OFFLOADED: https'
  241.  
  242. backend default {
  243. # .host = "localhost";
  244. .host = "127.0.0.1";
  245. .port = "8080";
  246. .first_byte_timeout = 3600s;
  247. .between_bytes_timeout = 180s;
  248. # .probe = {
  249. # .url = "/pub/health_check.php";
  250. # .timeout = 2s;
  251. # .interval = 5s;
  252. # .window = 10;
  253. # .threshold = 5;
  254. # }
  255. }
  256.  
  257. acl purge {
  258. "localhost";
  259. }
  260.  
  261. sub vcl_recv {
  262. if (req.method == "PURGE") {
  263. if (client.ip !~ purge) {
  264. return (synth(405, "Method not allowed"));
  265. }
  266. # To use the X-Pool header for purging varnish during automated deployments, make sure the X-Pool header
  267. # has been added to the response in your backend server config. This is used, for example, by the
  268. # capistrano-magento2 gem for purging old content from varnish during it's deploy routine.
  269. if (!req.http.X-Magento-Tags-Pattern && !req.http.X-Pool) {
  270. return (synth(400, "X-Magento-Tags-Pattern or X-Pool header required"));
  271. }
  272. if (req.http.X-Magento-Tags-Pattern) {
  273. ban("obj.http.X-Magento-Tags ~ " + req.http.X-Magento-Tags-Pattern);
  274. }
  275. if (req.http.X-Pool) {
  276. ban("obj.http.X-Pool ~ " + req.http.X-Pool);
  277. }
  278. #Added to test removing Varnish "Error" page on successful purge
  279. ban("obj.http.X-Magento-Tags ~ " + req.http.X-Magento-Tags-Pattern);
  280. #End
  281. return (synth(200, "Purged"));
  282. }
  283.  
  284.  
  285.  
  286. if (req.url == "/sitemap.xml") {
  287. return(pass);
  288. }
  289.  
  290. if (req.method != "GET" &&
  291. req.method != "HEAD" &&
  292. req.method != "PUT" &&
  293. req.method != "POST" &&
  294. req.method != "TRACE" &&
  295. req.method != "OPTIONS" &&
  296. req.method != "DELETE") {
  297. /* Non-RFC2616 or CONNECT which is weird. */
  298. return (pipe);
  299. }
  300.  
  301. # We only deal with GET and HEAD by default
  302. if (req.method != "GET" && req.method != "HEAD") {
  303. return (pass);
  304. }
  305.  
  306. # Bypass shopping cart, checkout and search requests
  307. 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") {
  308. return (pass);
  309. }
  310.  
  311. # Bypass health check requests
  312. if (req.url ~ "/pub/health_check.php") {
  313. return (pass);
  314. }
  315.  
  316. # Set initial grace period usage status
  317. set req.http.grace = "none";
  318.  
  319. # normalize url in case of leading HTTP scheme and domain
  320. set req.url = regsub(req.url, "^http[s]?://", "");
  321.  
  322. # collect all cookies
  323. std.collect(req.http.Cookie);
  324.  
  325. # Compression filter. See https://www.varnish-cache.org/trac/wiki/FAQ/Compression
  326. if (req.http.Accept-Encoding) {
  327. if (req.url ~ "\.(jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf|flv)$") {
  328. # No point in compressing these
  329. unset req.http.Accept-Encoding;
  330. } elsif (req.http.Accept-Encoding ~ "gzip") {
  331. set req.http.Accept-Encoding = "gzip";
  332. } elsif (req.http.Accept-Encoding ~ "deflate" && req.http.user-agent !~ "MSIE") {
  333. set req.http.Accept-Encoding = "deflate";
  334. } else {
  335. # unkown algorithm
  336. unset req.http.Accept-Encoding;
  337. }
  338. }
  339.  
  340. # Remove Google gclid parameters to minimize the cache objects
  341. set req.url = regsuball(req.url,"\?gclid=[^&]+$",""); # strips when QS = "?gclid=AAA"
  342. set req.url = regsuball(req.url,"\?gclid=[^&]+&","?"); # strips when QS = "?gclid=AAA&foo=bar"
  343. set req.url = regsuball(req.url,"&gclid=[^&]+",""); # strips when QS = "?foo=bar&gclid=AAA" or QS = "?foo=bar&gclid=AAA&bar=baz"
  344.  
  345. # Remove has_js and Cloudflare/Google Analytics __* cookies.
  346. set req.http.Cookie = regsuball(req.http.Cookie, "(^|;\s*)(_[_a-z]+|has_js)=[^;]*", "");
  347. # Remove a ";" prefix, if present.
  348. set req.http.Cookie = regsub(req.http.Cookie, "^;\s*", "");
  349.  
  350. #Start strip te mailchimp crap in URLs
  351. if (req.url ~ "(\?|&)(gclid|cx|ie|cof|siteurl|zanpid|origin|mc_[a-z]+|utm_[a-z]+)=") {
  352. set req.url = regsuball(req.url, "(gclid|cx|ie|cof|siteurl|zanpid|origin|mc_[a-z]+|utm_[a-z]+)=[-_A-z0-9+()%.]+&?", "");
  353. set req.url = regsub(req.url, "[?|&]+$", "");
  354. }
  355. #End strip the mailchimp crap in URLs
  356.  
  357. # Static files caching
  358. if (req.url ~ "^/(pub/)?(media|static)/") {
  359. # Static files should not be cached by default
  360. #return (pass);
  361.  
  362. # 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
  363. unset req.http.Https;
  364. unset req.http.SSL-OFFLOADED;
  365. unset req.http.Cookie;
  366. }
  367.  
  368. return (hash);
  369. }
  370.  
  371. sub vcl_hash {
  372. if (req.http.cookie ~ "X-Magento-Vary=") {
  373. hash_data(regsub(req.http.cookie, "^.*?X-Magento-Vary=([^;]+);*.*$", "\1"));
  374. }
  375.  
  376. # For multi site configurations to not cache each other's content
  377. if (req.http.host) {
  378. hash_data(req.http.host);
  379. } else {
  380. hash_data(server.ip);
  381. }
  382.  
  383. # To make sure http users don't see ssl warning
  384. if (req.http.SSL-OFFLOADED) {
  385. hash_data(req.http.SSL-OFFLOADED);
  386. }
  387.  
  388. }
  389.  
  390. sub vcl_backend_response {
  391.  
  392. #Disabed on stage for testing
  393. # set beresp.grace = 3d;
  394.  
  395. if (beresp.http.content-type ~ "text") {
  396. set beresp.do_esi = true;
  397. }
  398.  
  399. if (bereq.url ~ "\.js$" || beresp.http.content-type ~ "text") {
  400. set beresp.do_gzip = true;
  401. }
  402.  
  403. if (beresp.http.X-Magento-Debug) {
  404. set beresp.http.X-Magento-Cache-Control = beresp.http.Cache-Control;
  405. }
  406.  
  407. # cache only successfully responses and 404s
  408. # if (beresp.status != 200 && beresp.status != 404) {
  409. if (beresp.status != 200) {
  410. set beresp.ttl = 0s;
  411. set beresp.uncacheable = true;
  412. return (deliver);
  413. } elsif (beresp.http.Cache-Control ~ "private") {
  414. set beresp.uncacheable = true;
  415. set beresp.ttl = 8640000s;
  416. return (deliver);
  417. }
  418.  
  419. # validate if we need to cache it and prevent from setting cookie
  420. # images, css and js are cacheable by default so we have to remove cookie also
  421. if (beresp.ttl > 0s && (bereq.method == "GET" || bereq.method == "HEAD")) {
  422. unset beresp.http.set-cookie;
  423. unset beresp.http.expires;
  424. set beresp.ttl = 86400s;
  425. }
  426.  
  427. # If page is not cacheable then bypass varnish for 2 minutes as Hit-For-Pass
  428. if (beresp.ttl <= 0s ||
  429. beresp.http.Surrogate-control ~ "no-store" ||
  430. (!beresp.http.Surrogate-Control &&
  431. beresp.http.Cache-Control ~ "no-cache|no-store") ||
  432. beresp.http.Vary == "*") {
  433. # Mark as Hit-For-Pass for the next 2 minutes
  434. set beresp.ttl = 120s;
  435. set beresp.uncacheable = true;
  436. }
  437.  
  438.  
  439. }
  440.  
  441. sub vcl_deliver {
  442. if (resp.http.X-Magento-Debug) {
  443. if (resp.http.x-varnish ~ " ") {
  444. set resp.http.X-Magento-Cache-Debug = "HIT";
  445. set resp.http.Grace = req.http.grace;
  446. } else {
  447. set resp.http.X-Magento-Cache-Debug = "MISS";
  448. }
  449. } else {
  450. unset resp.http.Age;
  451. }
  452.  
  453. # Not letting browser to cache non-static files.
  454. if (resp.http.Cache-Control !~ "private" && req.url !~ "^/(pub/)?(media|static)/") {
  455. set resp.http.Pragma = "no-cache";
  456. set resp.http.Expires = "-1";
  457. set resp.http.Cache-Control = "no-store, no-cache, must-revalidate, max-age=0";
  458. }
  459.  
  460. unset resp.http.X-Magento-Debug;
  461. unset resp.http.X-Magento-Tags;
  462. unset resp.http.X-Powered-By;
  463. unset resp.http.Server;
  464. unset resp.http.X-Varnish;
  465. unset resp.http.Via;
  466. unset resp.http.Link;
  467. }
  468.  
  469. sub vcl_hit {
  470. if (obj.ttl >= 0s) {
  471. # Hit within TTL period
  472. return (deliver);
  473. }
  474. if (std.healthy(req.backend_hint)) {
  475. if (obj.ttl + 300s > 0s) {
  476. # Hit after TTL expiration, but within grace period
  477. set req.http.grace = "normal (healthy server)";
  478. return (deliver);
  479. } else {
  480. # Hit after TTL and grace expiration
  481. return (miss);
  482. }
  483. } else {
  484. # server is not healthy, retrieve from cache
  485. set req.http.grace = "unlimited (unhealthy server)";
  486. return (deliver);
  487. }
  488. }
  489.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement