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