Advertisement
tomasnorre

Varnish + TYPO3

Dec 3rd, 2012
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. backend default {
  2. .host = "192.168.1.100";
  3. .port = "80";
  4. }
  5.  
  6.  
  7. acl typo3_purge {
  8. "localhost";
  9. "192.168.1.101";
  10. }
  11.  
  12. sub vcl_recv {
  13. # Set backend
  14. set req.backend = default;
  15.  
  16. // Banning
  17. if (req.request == "BAN") {
  18. if ( ! client.ip ~ typo3_purge) {
  19. error 405 "Not allowed.";
  20. }
  21. if ( ! req.http.Ban-Expression) {
  22. error 400 "Ban-Expression missing.";
  23. }
  24. ban("" + req.http.Ban-Expression);
  25.  
  26. # Throw a synthetic page so the request wont go to the backend.
  27. error 200 "Ban added";
  28. }
  29.  
  30. // Purging
  31. if (req.request == "PURGE") {
  32. if ( ! client.ip ~ typo3_purge) {
  33. error 405 "Not allowed.";
  34. }
  35. // Remove the port from the host name
  36. set req.http.host = regsub(req.http.host, "([^:]+).*", "\1");
  37. return (lookup);
  38. }
  39.  
  40.  
  41.  
  42.  
  43. # Set a unique cache header with client ip
  44. if (req.http.x-forwarded-for) {
  45. set req.http.X-Forwarded-For = req.http.X-Forwarded-For + ", " + client.ip;
  46. } else {
  47. set req.http.X-Forwarded-For = client.ip;
  48. }
  49.  
  50. # Always allow post request to be sent to the backend but not cached
  51. if (req.request == "POST") {
  52. ban("req.url == " + req.url);
  53. set req.http.X-Test = req.url;
  54. return (pass);
  55. }
  56. if (req.request != "GET" &&
  57. req.request != "HEAD" &&
  58. req.request != "PUT" &&
  59. req.request != "POST" &&
  60. req.request != "TRACE" &&
  61. req.request != "OPTIONS" &&
  62. req.request != "DELETE") {
  63. # Pass to backend until it's closed
  64. return (pipe);
  65. }
  66.  
  67. # If neither get nor post request, send to backend but not cached
  68. if (req.request != "GET" && req.request != "HEAD") {
  69. return (pass);
  70. }
  71.  
  72. # If any autorisation was set do not cache
  73. if (req.http.Authorization || req.http.Cookie ~ "fe_typo_user") {
  74. return (pass);
  75. }
  76.  
  77. # If we work in backend
  78. if (req.http.Cookie ~ "be_typo_user") {
  79. # Delete cache depending on TYPO3 cache control
  80. if (req.http.Cache-Control ~ "no-cache") {
  81. set req.ttl = 0s;
  82. ban("req.url == " + req.url);
  83. }
  84. return (pass);
  85. }
  86. else {
  87. # Delete cookie
  88. unset req.http.Cookie;
  89. }
  90.  
  91. # Lookup in cache
  92. return (lookup);
  93. }
  94.  
  95. sub vcl_fetch {
  96. # Set default cache to 12 hours
  97. set beresp.ttl = 12h;
  98.  
  99. # Deliver old content up to 1 day
  100. set req.grace = 24h;
  101.  
  102. # Set cache for 2 days
  103. if (req.url ~ "\.(jpeg|jpg|png|gif|ico|swf|js|css|txt|gz|zip|rar|bz2|tgz|tbz|html|htm|pdf|pls|torrent)$") {
  104. set beresp.ttl = 48h;
  105. }
  106.  
  107. # Delete cookie
  108. if (req.url ~ "^/typo3") {
  109. }
  110. else {
  111. if (req.request == "POST") {
  112. }
  113. else {
  114. unset beresp.http.Set-Cookie;
  115. }
  116. }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement