Advertisement
Guest User

Untitled

a guest
Jul 27th, 2011
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 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. // Remove has_js and Google Analytics __* cookies.
  23. set req.http.Cookie = regsuball(req.http.Cookie, "(^|;\s*)(__[a-z]+|has_js)=[^;]*", "");
  24.  
  25. // Remove a ";" prefix, if present.
  26. set req.http.Cookie = regsub(req.http.Cookie, "^;\s*", "");
  27.  
  28. // Remove empty cookies.
  29. if (req.http.Cookie ~ "^\s*$") {
  30. unset req.http.Cookie;
  31. }
  32.  
  33. if (req.request == "PURGE") {
  34. if (!client.ip ~ purge) {
  35. error 405 "Not allowed.";
  36. }
  37. ban ("req.url ~ " + req.url + " && req.http.host == " + req.http.host);
  38. error 200 "Purged.";
  39. }
  40. }
  41.  
  42. sub vcl_hash {
  43. if (req.http.Cookie) {
  44. hash_data(req.http.Cookie);
  45. }
  46. }
  47.  
  48. sub vcl_fetch {
  49.  
  50. // Strip cookies for static files:
  51. 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)$") {
  52. unset beresp.http.set-cookie;
  53. }
  54.  
  55. // Varnish determined the object was not cacheable
  56. if (beresp.ttl == 0s) {
  57. set beresp.http.X-Cacheable = "NO:Not Cacheable";
  58. }
  59.  
  60. // You don't wish to cache content for logged in users
  61. elsif(req.http.Cookie ~"(UserID|_session)") {
  62. set beresp.http.X-Cacheable = "NO:Got Session";
  63. return(hit_for_pass);
  64. }
  65.  
  66. // You are respecting the Cache-Control=private header from the backend
  67. elsif ( beresp.http.Cache-Control ~ "private") {
  68. set beresp.http.X-Cacheable = "NO:Cache-Control=private";
  69. return(hit_for_pass);
  70. }
  71.  
  72. // You are extending the lifetime of the object artificially
  73. elsif ( beresp.ttl < 1s ) {
  74. set beresp.ttl = 300s;
  75. set beresp.grace = 300s;
  76. set beresp.http.X-Cacheable = "YES:Forced";
  77. }
  78.  
  79. // Varnish determined the object was cacheable
  80. else {
  81. set beresp.http.X-Cacheable = "YES";
  82. }
  83.  
  84. return(deliver);
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement