Advertisement
Guest User

varnish vcl

a guest
Jul 9th, 2010
1,790
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.55 KB | None | 0 0
  1. backend default {
  2. .host = "127.0.0.1";
  3. .port = "8080";
  4. .connect_timeout = 600s;
  5. .first_byte_timeout = 600s;
  6. .between_bytes_timeout = 600s;
  7. }
  8. acl purge {
  9. "localhost";
  10. "127.0.0.1";
  11. "10.129.22.21";
  12.  
  13.  
  14. }
  15. acl allowservers {
  16. "10.129.22.21";
  17. }
  18. sub vcl_recv {
  19. if (req.request == "PURGE") {
  20. if (!client.ip ~ purge) {
  21. error 405 "Not allowed.";
  22. }
  23. purge("req.url ~ " req.url);
  24. }
  25. // Remove has_js and Google Analytics cookies.
  26. set req.http.Cookie = regsuball(req.http.Cookie, "(^|;\s*)(__[a-z]+|has_js)=[^;]*", "");
  27. // Remove a ";" prefix, if present.
  28. set req.http.Cookie = regsub(req.http.Cookie, "^;\s*", "");
  29. // Remove empty cookies.
  30. if (req.http.Cookie ~ "^\s*$") {
  31. unset req.http.Cookie;
  32. }
  33. // No varnish for update.php, cron.php, xmlrpc.php
  34. if (req.url ~ "cron\.php|update\.php|xmlrpc\.php") {
  35. if (!client.ip ~ allowservers) {
  36. error 403 "Not allowed.";
  37. } else {
  38. return(pass);
  39. }
  40. }
  41. if (req.request == "GET" && req.url ~ "^/sites/") {
  42. // we only ever want to deal with GET requests, we are working
  43. // on the assumption that everything in sites is served the same
  44. // to all users so we don't want the cookie */
  45. unset req.http.cookie;
  46. #pass;
  47. return(lookup);
  48. }
  49. if (req.request == "GET" && req.url ~ "^/flash/") {
  50. #unset req.http.cookie;
  51. return(lookup);
  52. }
  53. if (req.request == "GET" && req.url ~ "^/files/") {
  54. unset req.http.cookie;
  55. return(lookup);
  56. }
  57. #if (req.request != "GET" && req.request != "HEAD") {
  58. # return(pipe);
  59. #}
  60. #if (req.http.Authenticate || req.http.Authorization) {
  61. # return(pipe);
  62. #}
  63. #if (req.http.Cookie && req.http.Cookie ~ "authtoken=") {
  64. # return(pipe);
  65. #}
  66. // Normalize the Accept-Encoding header
  67. // as per: http://varnish-cache.org/wiki/FAQ/Compression
  68. if (req.http.Accept-Encoding) {
  69. if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg)$") {
  70. # No point in compressing these
  71. remove req.http.Accept-Encoding;
  72. } elsif (req.http.Accept-Encoding ~ "gzip") {
  73. set req.http.Accept-Encoding = "gzip";
  74. } elsif (req.http.Accept-Encoding ~ "deflate") {
  75. set req.http.Accept-Encoding = "deflate";
  76. } else {
  77. # unkown algorithm
  78. remove req.http.Accept-Encoding;
  79. }
  80. }
  81. // Let's have a little grace
  82. set req.grace = 30s;
  83. }
  84. ### Strip any cookies before an image/js/css is inserted into cache.
  85. ### Also: future-support for ESI.
  86. sub vcl_fetch {
  87. if (beresp.status == 302 || beresp.status == 301) {
  88. return(pass);
  89. }
  90. if (req.request == "GET" && req.url ~ "^/sites/") {
  91. // we can unset the Cookie Drupal adds, set a lifetime for the object
  92. // and make it cacheable */
  93. unset beresp.http.Set-Cookie;
  94. set beresp.cacheable = true;
  95. # we can set how long Varnish will keep the object here, or later
  96. #set beresp.ttl = 30m;
  97. set beresp.ttl = 604800s;
  98. # debug add this and you'll see it in the headers if we came here
  99. #set beresp.http.X-Drupal-Varnish-Debug = "1";
  100. set beresp.http.X-Sites-Directory = "sites";
  101. }
  102. if (req.request == "GET" && req.url ~ "^/files/") {
  103. unset beresp.http.Set-Cookie;
  104. set beresp.cacheable = true;
  105. set beresp.ttl = 604800s;
  106. set beresp.http.X-Files-Directory = "files";
  107. }
  108. if (req.request == "GET" && req.url ~ "^/flash/") {
  109. unset beresp.http.Set-Cookie;
  110. set beresp.cacheable = true;
  111. set beresp.ttl = 604800s;
  112. set beresp.http.X-Varnish-FLASH = "flash!!!!";
  113. }
  114. if (beresp.cacheable) {
  115. // Things common to all cacheable objects, here it removes
  116. // the Expires that are often in the past, sets cache control
  117. // and how long varnish will keep it
  118. // and mark it for delivery (and storing) */
  119. set beresp.cacheable = true;
  120. unset beresp.http.expires;
  121. set beresp.http.cache-control = "max-age = 1900";
  122. set beresp.ttl = 1w;
  123. set beresp.http.magicmarker = "1";
  124. set beresp.http.cachable = "1";
  125. return(deliver);
  126. }
  127. if (req.url ~ "\.(png|gif|jpg|swf|css|js)$") {
  128. unset beresp.http.set-cookie;
  129. set beresp.http.X-Files = "png|gif|jpg|swf|css|js";
  130. }
  131. esi;
  132. }
  133. sub vcl_hash {
  134. if (req.http.Cookie) {
  135. set req.hash += req.http.Cookie;
  136. }
  137. }
  138. sub vcl_deliver {
  139. if (resp.http.magicmarker) {
  140. /* unset marker and serve it for upstream as new */
  141. unset resp.http.magicmarker;
  142. set resp.http.age = "0";
  143. }
  144. }
  145. sub vcl_error {
  146. etc....
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement