Advertisement
Guest User

Untitled

a guest
Feb 18th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.72 KB | None | 0 0
  1.  
  2. backend images_gluster1 {
  3. .host = "192.168.0.50";
  4. .port = "82";
  5. .connect_timeout = 15s;
  6. .first_byte_timeout = 60s;
  7. .between_bytes_timeout = 15s;
  8. # Backend polling: http://varnish.projects.linpro.no/wiki/BackendPolling
  9. .probe = {
  10. .url = "/polling/tour_search.png";
  11. .timeout = 10s;
  12. .interval = 1m;
  13. .window = 3;
  14. .threshold = 1;
  15. }
  16. }
  17.  
  18. backend resources_gluster1 {
  19. .host = "192.168.0.50";
  20. .port = "83";
  21. .connect_timeout = 15s;
  22. .first_byte_timeout = 60s;
  23. .between_bytes_timeout = 15s;
  24. # Backend polling: http://varnish.projects.linpro.no/wiki/BackendPolling
  25. .probe = {
  26. .url = "/polling/tour_search.png";
  27. .timeout = 10s;
  28. .interval = 1m;
  29. .window = 3;
  30. .threshold = 1;
  31. }
  32. }
  33.  
  34. sub vcl_init {
  35. # define directors and add backends
  36. # resources
  37. new res = directors.round_robin();
  38. res.add_backend(resources_gluster1);
  39. res.add_backend(resources_gluster2);
  40. res.add_backend(resources_gluster3);
  41.  
  42. # images
  43. new img = directors.round_robin();
  44. img.add_backend(images_gluster1);
  45. img.add_backend(images_gluster2);
  46. img.add_backend(images_gluster3);
  47.  
  48. }
  49.  
  50. sub vcl_hash {
  51. hash_data(req.url);
  52. hash_data(req.http.host);
  53. if (req.url ~ "^/api/" && req.http.Accept ~ "json" ) {
  54. hash_data(req.http.Accept);
  55. }
  56. return(lookup);
  57. }
  58.  
  59. sub vcl_hit {
  60. # Called when a cache lookup is successful.
  61. if (obj.ttl >= 0s) {
  62. # A pure unadultered hit, deliver it
  63. return (deliver);
  64. }
  65.  
  66. if (std.healthy(req.backend_hint)) {
  67. # Backend is healthy. Limit age to 30s.
  68. if (obj.ttl + 30s > 0s) {
  69. #set req.http.grace = "normal(limited)";
  70. return (deliver);
  71. } else {
  72. # No candidate for grace. Fetch a fresh object.
  73. return(miss);
  74. }
  75. } else {
  76. # backend is sick - use full grace
  77. if (obj.ttl + obj.grace > 0s) {
  78. #set req.http.grace = "full";
  79. return (deliver);
  80. } else {
  81. # no graced object.
  82. return (miss);
  83. }
  84. }
  85.  
  86. # fetch & deliver once we get the result
  87. return (miss); # Dead code, keep as a safeguard
  88. }
  89.  
  90. sub vcl_miss {
  91. # Called after a cache lookup if the requested document was not found in the cache. Its purpose
  92. # is to decide whether or not to attempt to retrieve the document from the backend, and which
  93. # backend to use.
  94.  
  95. return (fetch);
  96. }
  97.  
  98. sub vcl_backend_response {
  99. # Happens after we have read the response headers from the backend.
  100. #
  101. # Here you clean the response headers, removing silly Set-Cookie headers
  102. # and other mistakes your backend does.
  103.  
  104. # Set server header
  105. # set req.grace = 3h;
  106. unset beresp.http.Server;
  107. set beresp.http.Server = "Apache/2 (CBM-64)";
  108.  
  109. # Remove E-Tags from all replies except from json
  110. if (! (bereq.url ~ "\.json" || bereq.url ~ "\.jsonp")) {
  111. unset beresp.http.Etag;
  112. }
  113.  
  114. # Don't cache 404 responses
  115. if (beresp.status == 404) {
  116. set beresp.ttl = 10s;
  117. set beresp.uncacheable = true;
  118. return (deliver);
  119. }
  120. else if (beresp.status<300) {
  121. set beresp.http.X-Varnish-Comment = "Caching rule applied";
  122. if (bereq.url ~ "^/img/" || bereq.url ~ "^/img2/" ) {
  123. unset bereq.http.Cookie;
  124. unset beresp.http.Set-Cookie;
  125. set beresp.ttl = 31d;
  126. set beresp.http.Cache-Control = "max-age=2678400";
  127. return(deliver);
  128. }
  129. # If no cookie set: Use default caching time
  130. if (!bereq.http.Cookie) {
  131. set beresp.ttl = 15m;
  132. set beresp.http.Cache-Control = "max-age=900";
  133. return(deliver);
  134. } else {
  135. set beresp.http.X-Varnish-Comment = "Logged in";
  136. set beresp.uncacheable = true;
  137. return(deliver);
  138. }
  139. } else {
  140. # Use very short caching time for error messages - giving the system the chance to recover
  141. set beresp.ttl = 120s;
  142. unset beresp.http.Cache-Control;
  143. return(deliver);
  144. }
  145. }
  146.  
  147. sub vcl_deliver {
  148. # Happens when we have all the pieces we need, and are about to send the
  149. # response to the client.
  150. #
  151. # You can do accounting or modifying the final object here.
  152. if (obj.hits > 0) {
  153. set resp.http.X-Cache = "HIT";
  154. } else {
  155. set resp.http.X-Cache = "MISS";
  156. }
  157.  
  158. set resp.http.X-Cache-Hits = obj.hits;
  159.  
  160. return(deliver);
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement