Guest User

Untitled

a guest
May 28th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1. vcl 4.0;
  2.  
  3. import std;
  4. # The minimal Varnish version is 4.0
  5.  
  6. backend default {
  7. .host = "192.168.1.20";
  8. .port = "8080";
  9. }
  10.  
  11. acl purge {
  12. "192.168.1.20";
  13. }
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20. sub vcl_recv {
  21. if (req.method == "PURGE") {
  22. if (client.ip !~ purge) {
  23. return (synth(405, "Method not allowed"));
  24. }
  25. if (!req.http.X-Magento-Tags-Pattern) {
  26. return (synth(400, "X-Magento-Tags-Pattern header required"));
  27. }
  28. ban("obj.http.X-Magento-Tags ~ " + req.http.X-Magento-Tags-Pattern);
  29. return (synth(200, "Purged"));
  30. }
  31.  
  32. if (req.method != "GET" &&
  33. req.method != "HEAD" &&
  34. req.method != "PUT" &&
  35. req.method != "POST" &&
  36. req.method != "TRACE" &&
  37. req.method != "OPTIONS" &&
  38. req.method != "DELETE") {
  39. /* Non-RFC2616 or CONNECT which is weird. */
  40. return (pipe);
  41. }
  42.  
  43.  
  44.  
  45.  
  46. # We only deal with GET and HEAD by default
  47. if (req.method != "GET" && req.method != "HEAD") {
  48. return (pass);
  49. }
  50.  
  51. # Bypass shopping cart and checkout requests
  52. if (req.url ~ "/checkout") {
  53. return (pass);
  54. }
  55.  
  56. # normalize url in case of leading HTTP scheme and domain
  57. set req.url = regsub(req.url, "^http[s]?://", "");
  58.  
  59. # collect all cookies
  60. std.collect(req.http.Cookie);
  61.  
  62. # static files are always cacheable. remove SSL flag and cookie
  63. if (req.url ~ "^/(pub/)?(media|static)/.*.(ico|css|js|jpg|jpeg|png|gif|tiff|bmp|mp3|ogg|svg|swf|woff|woff2|eot|ttf|otf)$") {
  64. unset req.http.Https;
  65. unset req.http.Cookie;
  66. }
  67.  
  68. return (hash);
  69. }
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76. sub vcl_hash {
  77. if (req.http.cookie ~ "X-Magento-Vary=") {
  78. hash_data(regsub(req.http.cookie, "^.*?X-Magento-Vary=([^;]+);*.*$", "1"));
  79. }
  80.  
  81. }
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88. sub vcl_backend_response {
  89. if (beresp.http.content-type ~ "text") {
  90. set beresp.do_esi = true;
  91. }
  92.  
  93. if (bereq.url ~ ".js$" || beresp.http.content-type ~ "text") {
  94. set beresp.do_gzip = true;
  95. }
  96.  
  97. # cache only successfully responses and 404s
  98. if (beresp.status != 200 && beresp.status != 404) {
  99. set beresp.ttl = 0s;
  100. set beresp.uncacheable = true;
  101. return (deliver);
  102. } elsif (beresp.http.Cache-Control ~ "private") {
  103. set beresp.uncacheable = true;
  104. set beresp.ttl = 86400s;
  105. return (deliver);
  106. }
  107.  
  108. if (beresp.http.X-Magento-Debug) {
  109. set beresp.http.X-Magento-Cache-Control = beresp.http.Cache-Control;
  110. }
  111.  
  112. # validate if we need to cache it and prevent from setting cookie
  113. # images, css and js are cacheable by default so we have to remove cookie also
  114. if (beresp.ttl > 0s && (bereq.method == "GET" || bereq.method == "HEAD")) {
  115. unset beresp.http.set-cookie;
  116. if (bereq.url !~ ".(ico|css|js|jpg|jpeg|png|gif|tiff|bmp|gz|tgz|bz2|tbz|mp3|ogg|svg|swf|woff|woff2|eot|ttf|otf)(?|$)") {
  117. set beresp.http.Pragma = "no-cache";
  118. set beresp.http.Expires = "-1";
  119. set beresp.http.Cache-Control = "no-store, no-cache, must-revalidate, max-age=0";
  120. set beresp.grace = 1m;
  121. }
  122. }
  123. return (deliver);
  124. }
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131. sub vcl_deliver {
  132. if (resp.http.X-Magento-Debug) {
  133. if (resp.http.x-varnish ~ " ") {
  134. set resp.http.X-Magento-Cache-Debug = "HIT";
  135. } else {
  136. set resp.http.X-Magento-Cache-Debug = "MISS";
  137. }
  138. } else {
  139. unset resp.http.Age;
  140. }
  141.  
  142. }
  143.  
  144. server {
  145. listen 443 ssl;
  146.  
  147. server_name magentotest.devcom;
  148. ssl_certificate /etc/ssl/certs/nginx.crt;
  149. ssl_certificate_key /etc/ssl/certs/nginx.key;
  150.  
  151. location / {
  152. proxy_pass http://127.0.0.1:80;
  153. proxy_set_header X-Real-IP $remote_addr;
  154. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  155. proxy_set_header X-Forwarded-Proto https;
  156. proxy_set_header X-Forwarded-Port 443;
  157. proxy_set_header Host $host;
  158. }
  159. }
Add Comment
Please, Sign In to add comment