varnish.vcl 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # See https://github.com/EFForg/action-center-platform/wiki/Deployment-Notes#cache-configuration
  2. sub vcl_recv {
  3. #FASTLY recv
  4. if (req.request != "HEAD" && req.request != "GET" && req.request != "FASTLYPURGE") {
  5. return(pass);
  6. }
  7. if (req.http.cookie ~ "logged_in" && req.url !~ "^/assets/") {
  8. set req.hash_always_miss = true;
  9. return(pass);
  10. }
  11. if (req.url !~ "^/(ahoy)/") {
  12. unset req.http.Cookie;
  13. }
  14. return(lookup);
  15. }
  16. sub vcl_fetch {
  17. if (req.http.cookie !~ "logged_in" && req.url !~ "^/(login)|(register)|(confirmation/new)|(unlock/new)|(password/new)|(password/edit)|(ahoy/)") {
  18. unset beresp.http.Set-Cookie;
  19. }
  20. #FASTLY fetch
  21. if ((beresp.status == 500 || beresp.status == 503) && req.restarts < 1 && (req.request == "GET" || req.request == "HEAD")) {
  22. restart;
  23. }
  24. if (req.restarts > 0) {
  25. set beresp.http.Fastly-Restarts = req.restarts;
  26. }
  27. if (beresp.http.Set-Cookie) {
  28. set req.http.Fastly-Cachetype = "SETCOOKIE";
  29. return(pass);
  30. }
  31. if (beresp.http.Cache-Control ~ "private") {
  32. set req.http.Fastly-Cachetype = "PRIVATE";
  33. return(pass);
  34. }
  35. if (beresp.status == 500 || beresp.status == 503) {
  36. set req.http.Fastly-Cachetype = "ERROR";
  37. set beresp.ttl = 1s;
  38. set beresp.grace = 5s;
  39. return(deliver);
  40. }
  41. if (beresp.http.Expires || beresp.http.Surrogate-Control ~ "max-age" || beresp.http.Cache-Control ~ "(s-maxage|max-age)") {
  42. # keep the ttl here
  43. } else {
  44. # apply the default ttl
  45. set beresp.ttl = 3600s;
  46. }
  47. return(deliver);
  48. }
  49. sub vcl_hit {
  50. #FASTLY hit
  51. if (!obj.cacheable) {
  52. return(pass);
  53. }
  54. return(deliver);
  55. }
  56. sub vcl_miss {
  57. #FASTLY miss
  58. return(fetch);
  59. }
  60. sub vcl_deliver {
  61. #FASTLY deliver
  62. return(deliver);
  63. }
  64. sub vcl_error {
  65. #FASTLY error
  66. }
  67. sub vcl_pass {
  68. #FASTLY pass
  69. }
  70. sub vcl_log {
  71. #FASTLY log
  72. }