Simple Varnish Config
Config is an exact copy of https://gist.github.com/jeremyjbowers/1542949. Copying it here verbatim to avoid bit rot.
1/*
2*
3* First, set up a backend to answer the request if there's not a cache hit.
4*
5*/
6backend default {
7
8 # Set a host.
9 .host = "192.168.1.100";
10
11 # Set a port. 80 is normal Web traffic.
12 .port = "8000";
13}
14/*
15*
16* Next, configure the "receive" subroutine.
17*
18*/
19sub vcl_recv {
20
21 # Use the backend we set up above to answer the request if it's not cached.
22 set req.backend = default;
23
24 # Pass the request along to lookup to see if it's in the cache.
25 return(lookup);
26}
27/*
28*
29* Next, let's set up the subroutine to deal with cache misses.
30*
31*/
32sub vcl_miss {
33
34 # We're not doing anything fancy. Just pass the request along to the
35 # subroutine which will fetch something from the backend.
36 return(fetch);
37}
38/*
39*
40* Now, let's set up a subroutine to deal with cache hits.
41*
42*/
43sub vcl_hit {
44
45 # Again, nothing fancy. Just pass the request along to the subroutine
46 # which will deliver a result from the cache.
47 return(deliver);
48}
49/*
50*
51* This is the subroutine which will fetch a response from the backend.
52* It's pretty fancy because this is where the basic logic for caching is set.
53*
54*/
55sub vcl_fetch {
56
57 # Get the response. Set the cache lifetime of the response to 1 hour.
58 set beresp.ttl = 1h;
59
60 # Indicate that this response is cacheable. This is important.
61 set beresp.http.X-Cacheable = "YES";
62
63 # Some backends *cough* Django *cough* will assign a Vary header for
64 # each User-Agent which visits the site. Varnish will store a separate
65 # copy of the page in the cache for each instance of the Vary header --
66 # one for each User-Agent which visits the site. This is bad. So we're
67 # going to strip away the Vary header.
68 unset beresp.http.Vary;
69
70 # Now pass this backend response along to the cache to be stored and served.
71 return(deliver);
72}
73/*
74*
75* Finally, let's set up a subroutine which will deliver a response to the client.
76*
77*/
78sub vcl_deliver {
79
80 # Nothing fancy. Just deliver the goods.
81 # Note: Both cache hits and cache misses will use this subroutine.
82 return(deliver);
83}