Advertisement
IchHabRecht

[VCL] Basic Varnish configuration for TYPO3

Sep 8th, 2012
658
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.54 KB | None | 0 0
  1. sub vcl_recv {
  2.         # Set backend
  3.         set req.backend = default;
  4.  
  5.         if (req.http.host ~ "gitweb.squeezebox.vm") {
  6.                 return (pass);
  7.         }
  8.  
  9.         # Set a unique cache header with client ip
  10.         if (req.http.x-forwarded-for) {
  11.                 set req.http.X-Forwarded-For = req.http.X-Forwarded-For + ", " + client.ip;
  12.         } else {
  13.                 set req.http.X-Forwarded-For = client.ip;
  14.         }
  15.  
  16.         # Always allow post request to be sent to the backend but not cached
  17.         if (req.request == "POST") {
  18.                 ban("req.url == " + req.url);
  19.                 set req.http.X-Test = req.url;
  20.                 return (pass);
  21.         }
  22.         if (req.request != "GET" &&
  23.         req.request != "HEAD" &&
  24.                 req.request != "PUT" &&
  25.                 req.request != "POST" &&
  26.                 req.request != "TRACE" &&
  27.                 req.request != "OPTIONS" &&
  28.                 req.request != "DELETE") {
  29.                 # Pass to backend until it's closed
  30.                 return (pipe);
  31.         }
  32.  
  33.         # If neither get nor post request, send to backend but not cached
  34.         if (req.request != "GET" && req.request != "HEAD") {
  35.                 return (pass);
  36.         }
  37.  
  38.         # If any autorisation was set do not cache
  39.         if (req.http.Authorization || req.http.Cookie ~ "fe_typo_user") {
  40.                 return (pass);
  41.         }
  42.  
  43.         # If we work in backend
  44.         if (req.http.Cookie ~ "be_typo_user") {
  45.                 # Delete cache depending on TYPO3 cache control
  46.                 if (req.http.Cache-Control ~ "no-cache") {
  47.                         set req.ttl = 0s;
  48.                         ban("req.url == " + req.url);
  49.                 }
  50.                 return (pass);
  51.         }
  52.         else {
  53.                 # Delete cookie
  54.                 unset req.http.Cookie;
  55.         }
  56.  
  57.         # Lookup in cache
  58.         return (lookup);
  59. }
  60.  
  61. sub vcl_fetch {
  62.         # Set default cache to 12 hours
  63.         set beresp.ttl = 12h;
  64.  
  65.         # Deliver old content up to 1 day
  66.         set req.grace = 24h;
  67.  
  68.         # Set cache for 2 days
  69.         if (req.url ~ "\.(jpeg|jpg|png|gif|ico|swf|js|css|txt|gz|zip|rar|bz2|tgz|tbz|html|htm|pdf|pls|torrent)$") {
  70.                 set beresp.ttl = 48h;
  71.         }
  72.  
  73.         # Delete cookie
  74.         if (req.url ~ "^/typo3") {
  75.         }
  76.         else {
  77.                 if (req.request == "POST") {
  78.                 }
  79.                 else {
  80.                         unset beresp.http.Set-Cookie;
  81.                 }
  82.         }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement