/silverlining/server-root/etc/varnish/default.vcl

https://bitbucket.org/ianb/silverlining/ · Varnish Configuration · 79 lines · 57 code · 6 blank · 16 comment · 0 complexity · 5f4bf4dfff980c0d84ab542a9d6e65b9 MD5 · raw file

  1. backend default {
  2. .host = "127.0.0.1";
  3. .port = "8080";
  4. }
  5. sub vcl_pipe {
  6. # Note that only the first request to the backend will have
  7. # X-Forwarded-For set. If you use X-Forwarded-For and want to
  8. # have it set for all requests, make sure to have:
  9. set req.http.connection = "close";
  10. # here. It is not set by default as it might break some broken web
  11. # applications, like IIS with NTLM authentication.
  12. return (pipe);
  13. }
  14. sub vcl_recv {
  15. set req.http.X-Varnish-IP = server.ip;
  16. # Add a unique header containing the client address
  17. remove req.http.X-Forwarded-For;
  18. set req.http.X-Forwarded-For = client.ip;
  19. if (req.request == "POST") {
  20. return(pass);
  21. }
  22. if (req.request != "GET" && req.request != "HEAD" &&
  23. req.request != "PUT" && req.request != "POST" &&
  24. req.request != "TRACE" && req.request != "OPTIONS" &&
  25. req.request != "DELETE") {
  26. # Non-RFC2616 or CONNECT which is weird. #
  27. return(pass);
  28. }
  29. if (req.http.Authorization) {
  30. # Not cacheable by default #
  31. return(pass);
  32. }
  33. }
  34. sub vcl_fetch {
  35. if(beresp.http.Pragma ~ "no-cache" ||
  36. beresp.http.Cache-Control ~ "no-cache" ||
  37. beresp.http.Cache-Control ~ "private") {
  38. return(pass);
  39. }
  40. if (beresp.status >= 300) {
  41. return(pass);
  42. }
  43. # Django regularly sends pages with Set-Cookie and cache control,
  44. # we'll ignore Cache-Control in that case, as there's no point to
  45. # caching something that sets a cookie.
  46. if (beresp.http.Set-Cookie) {
  47. unset beresp.http.Cache-Control;
  48. return(pass);
  49. }
  50. if (beresp.http.Cache-Control ~ "max-age" || beresp.http.Expires) {
  51. unset beresp.http.Set-Cookie;
  52. return(deliver);
  53. }
  54. # Apache adds Vary: X-Forwarded-For to each response, which would
  55. # mean a separate cache for each client; not our intent, so we'll
  56. # ignore it:
  57. set beresp.http.Vary = regsub(beresp.http.Vary, ",?X-Forwarded-For", "");
  58. return(pass);
  59. }
  60. sub vcl_hit {
  61. if (!obj.cacheable) {
  62. return(pass);
  63. }
  64. if (req.http.Cache-Control ~ "no-cache") {
  65. # Ignore requests via proxy caches, IE users and badly behaved crawlers
  66. # like msnbot that send no-cache with every request.
  67. if (! (req.http.Via || req.http.User-Agent ~ "bot|MSIE")) {
  68. set obj.ttl = 0s;
  69. return (restart);
  70. }
  71. }
  72. return(deliver);
  73. }