Advertisement
Guest User

Untitled

a guest
Aug 18th, 2010
456
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.91 KB | None | 0 0
  1. backend local {
  2. .host = "127.0.0.1";
  3. .port = "17000";
  4. }
  5.  
  6.  
  7. # TODO put health checks in the backends to check the
  8. # SI VIPs to move traffic away from a bad VIP
  9. director thermos round-robin {
  10. { .backend = {
  11. .host = "208.x.x.x";
  12. .port = "80";
  13. }
  14. }
  15.  
  16. { .backend = {
  17. .host = "208.x.x.x";
  18. .port = "80";
  19. }
  20. }
  21. }
  22.  
  23.  
  24.  
  25. acl purge {
  26. "38.x.x.0"/24;
  27. "208.x.x.0"/24;
  28. "10.101.0.0"/16;
  29. "localhost";
  30. }
  31.  
  32. sub vcl_recv {
  33. set req.backend = thermos;
  34. # if (req.restarts == 0) {
  35. # }
  36.  
  37. # so infuriating!!
  38. if (req.url ~ "^http://") {
  39. set req.url = regsub(req.url, "http://[^/]*", "");
  40. }
  41.  
  42. # MUCHO IMPORTANTE
  43. # http://varnish-cache.org/wiki/FAQ/Compression
  44. if (req.http.Accept-Encoding) {
  45. if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg)$" || req.url ~ ".*scaled.php.*" ) {
  46. # No point in compressing these
  47. remove req.http.Accept-Encoding;
  48. } elsif (req.http.Accept-Encoding ~ "gzip") {
  49. set req.http.Accept-Encoding = "gzip";
  50. } elsif (req.http.Accept-Encoding ~ "deflate") {
  51. set req.http.Accept-Encoding = "deflate";
  52. } else {
  53. # unkown encoding
  54. remove req.http.Accept-Encoding;
  55. }
  56. }
  57.  
  58. if (req.url ~ ".*scaled\.php.*server=&.*") {
  59. error 400 "Bad Request";
  60. }
  61.  
  62. if (req.request != "GET" && req.request != "HEAD") {
  63. # PURGE request if zope asks nicely
  64. if (req.request == "PURGE") {
  65. if (!client.ip ~ purge) {
  66. error 405 "Not allowed.";
  67. }
  68. return(lookup);
  69. }
  70. return(pipe);
  71. }
  72.  
  73. if (req.http.Expect) {
  74. return(pipe);
  75. }
  76.  
  77. if (req.http.Authenticate || req.http.Authorization) {
  78. return(pass);
  79. }
  80.  
  81. # We only care about the "__ac.*" cookies, used for authentication
  82. if (req.http.Cookie && req.http.Cookie ~ "__ac(|_(name|password|persistent))=") {
  83. return(pass);
  84. }
  85.  
  86. if (req.url ~ "^/healthz") {
  87. error 204 "health OK";
  88. }
  89.  
  90. # File type that we will always cache
  91. if (req.request == "GET" && req.url ~ "\.(gif|jpg|swf|css|js|png|jpg|jpeg|gif|png|tiff|tif|svg|swf|ico|css|js|vsd|doc|ppt|pps|xls|pdf|mp3|mp4|m4a|ogg|mov|avi|wmv|sxw|zip|gz|bz2|tgz|tar|rar|odc|odb|odf|odg|odi|odp|ods|odt|sxc|sxd|sxi|sxw|dmg|torrent|deb|msi|iso|rpm)$") {
  92. return(lookup);
  93. }
  94.  
  95. # normalize req.url to cut down on dups
  96. if (req.url ~ "^/+img[0-9]{1,4}/[0-9]{1,4}/.*\?.*$") {
  97. set req.url = regsub(req.url, "\?.*", "");
  98. }
  99.  
  100. if (req.request == "POST") {
  101. error 405 "Method Not Allowed";
  102. }
  103.  
  104. # force return(lookup) even when cookies are present
  105. if (req.request == "GET" && req.http.cookie) {
  106. return(lookup);
  107. }
  108. return(lookup);
  109. }
  110.  
  111.  
  112. sub vcl_fetch {
  113. if (beresp.http.Set-Cookie) {
  114. unset beresp.http.Set-Cookie;
  115. }
  116.  
  117. # force minimum ttl
  118. if (beresp.cacheable) {
  119. set beresp.ttl = 6h;
  120. /* Remove Expires from backend, it's not long enough */
  121. unset beresp.http.expires;
  122. /* Set how long Varnish will keep it */
  123. /* marker for vcl_deliver to reset Age: */
  124. set beresp.http.magicmarker = "1";
  125. }
  126.  
  127. remove beresp.http.X-Varnish-IP;
  128. remove beresp.http.X-Varnish-Port;
  129.  
  130. }
  131.  
  132. sub vcl_hit {
  133. # Do the PURGE thing
  134. if (req.request == "PURGE") {
  135. set obj.ttl = 0s;
  136. error 200 "Purged";
  137. } else {
  138. set obj.ttl = 12h;
  139. }
  140.  
  141.  
  142. }
  143.  
  144. sub vcl_miss {
  145. if (req.request == "PURGE") {
  146. error 404 "Not in cache";
  147. }
  148. set bereq.http.host = "desmondweb.<domain>.us";
  149. set bereq.http.X-Thermos-L7-Switch-Server-Type = "desmond_web";
  150.  
  151. }
  152.  
  153. sub vcl_hash {
  154. set req.hash += req.url;
  155. return(hash);
  156. }
  157.  
  158. sub vcl_deliver {
  159. if (resp.http.magicmarker) {
  160. /* Remove the magic marker */
  161. unset resp.http.magicmarker;
  162.  
  163. /* By definition we have a fresh object */
  164. set resp.http.age = "0";
  165. }
  166. set resp.http.X-Varnish-Hits = obj.hits;
  167. set resp.http.X-Varnish-IP = server.ip;
  168. set resp.http.X-Varnish-Port = server.port;
  169. return(deliver);
  170.  
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement