Advertisement
Guest User

Untitled

a guest
Sep 9th, 2011
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. backend apache {
  2. .host = "127.0.0.1";
  3. .port = "8080";
  4. }
  5.  
  6. acl purge {
  7. "localhost";
  8. "127.0.0.1";
  9. }
  10.  
  11. sub vcl_recv {
  12. // Attempt to pass the client ip through varnish from the load balancer
  13. remove req.http.X-Forwarded-For;
  14. set req.http.X-Forwarded-For = req.http.X-Cluster-Client-IP;
  15.  
  16. // Strip cookies for static files:
  17. if (req.url ~ "\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm)$") {
  18. unset req.http.Cookie;
  19. return(lookup);
  20. }
  21.  
  22. // Do not cache openx ads
  23. if (req.http.host ~ "openx.wellplayed.org") {
  24. return (pass);
  25. }
  26.  
  27. // Remove has_js and Google Analytics __* cookies.
  28. set req.http.Cookie = regsuball(req.http.Cookie, "(^|;\s*)(__[a-z]+|has_js)=[^;]*", "");
  29.  
  30. // Remove a ";" prefix, if present.
  31. set req.http.Cookie = regsub(req.http.Cookie, "^;\s*", "");
  32.  
  33. // Remove empty cookies.
  34. if (req.http.Cookie ~ "^\s*$") {
  35. unset req.http.Cookie;
  36. }
  37.  
  38. if (req.request == "PURGE") {
  39. if (!client.ip ~ purge) {
  40. error 405 "Not allowed.";
  41. }
  42. ban ("req.url ~ " + req.url + " && req.http.host == " + req.http.host);
  43. error 200 "Purged.";
  44. }
  45. }
  46.  
  47. sub vcl_hash {
  48. if (req.http.Cookie) {
  49. hash_data(req.http.Cookie);
  50. }
  51. }
  52.  
  53. sub vcl_fetch {
  54.  
  55. // Strip cookies for static files:
  56. if (req.url ~ "\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm)$") {
  57. unset beresp.http.set-cookie;
  58. }
  59.  
  60. // Varnish determined the object was not cacheable
  61. if (beresp.ttl == 0s) {
  62. set beresp.http.X-Cacheable = "NO:Not Cacheable";
  63. }
  64.  
  65. // You don't wish to cache content for logged in users
  66. elsif(req.http.Cookie ~"(UserID|_session)") {
  67. set beresp.http.X-Cacheable = "NO:Got Session";
  68. return(hit_for_pass);
  69. }
  70.  
  71. // You are respecting the Cache-Control=private header from the backend
  72. elsif ( beresp.http.Cache-Control ~ "private") {
  73. set beresp.http.X-Cacheable = "NO:Cache-Control=private";
  74. return(hit_for_pass);
  75. }
  76.  
  77. // You are extending the lifetime of the object artificially
  78. elsif ( beresp.ttl < 1s ) {
  79. set beresp.ttl = 300s;
  80. set beresp.grace = 300s;
  81. set beresp.http.X-Cacheable = "YES:Forced";
  82. }
  83.  
  84. // Varnish determined the object was cacheable
  85. else {
  86. set beresp.http.X-Cacheable = "YES";
  87. }
  88.  
  89. return(deliver);
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement