]> Sergey Matveev's repositories - public-inbox.git/blob - examples/varnish-4.vcl
examples: remove X-Forwarded-For mentions
[public-inbox.git] / examples / varnish-4.vcl
1 # Example VCL for Varnish 4.0 with public-inbox WWW code
2 # This is based on what shipped for 3.x a long time ago (I think)
3 # and I'm hardly an expert in VCL (nor should we expect anybody
4 # who maintains a public-inbox HTTP interface to be).
5 #
6 # It seems to work for providing some protection from traffic
7 # bursts; but perhaps the public-inbox WWW interface can someday
8 # provide enough out-of-the-box performance that configuration
9 # of an extra component is pointless.
10
11 vcl 4.0;
12 backend default {
13         .host = "127.0.0.1";
14         .port = "280";
15 }
16
17 sub vcl_recv {
18         if (req.method != "GET" &&
19                         req.method != "HEAD" &&
20                         req.method != "PUT" &&
21                         req.method != "POST" &&
22                         req.method != "TRACE" &&
23                         req.method != "OPTIONS" &&
24                         req.method != "DELETE") {
25                 /* Non-RFC2616 or CONNECT which is weird. */
26                 return (pipe);
27         }
28         if (req.method != "GET" && req.method != "HEAD") {
29                 /* We only deal with GET and HEAD by default */
30                 return (pass);
31         }
32         if (req.http.Authorization || req.http.Cookie) {
33                 /* Not cacheable by default */
34                 return (pass);
35         }
36         return (hash);
37 }
38
39 sub vcl_hash {
40         hash_data(req.url);
41         if (req.http.host) {
42                 hash_data(req.http.host);
43         } else {
44                 hash_data(server.ip);
45         }
46         if (req.http.X-Forwarded-Proto) {
47                 hash_data(req.http.X-Forwarded-Proto);
48         }
49         return (lookup);
50 }
51
52 sub vcl_backend_response {
53         set beresp.grace = 60s;
54         set beresp.do_stream = true;
55         if (beresp.ttl <= 0s ||
56                 beresp.http.Set-Cookie ||
57                 beresp.http.Vary == "*") {
58                 /* Mark as "Hit-For-Pass" for the next 2 minutes */
59                 set beresp.ttl = 120 s;
60                 set beresp.uncacheable = true;
61                 return (deliver);
62         } else {
63                 set beresp.ttl = 10s;
64         }
65         return (deliver);
66 }