/
default.vcl.j2
83 lines (74 loc) · 1.56 KB
/
default.vcl.j2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#
# --- THIS FILE IS AUTOMATICALLY PROVISIONED THROUGH ANSIBLE ---
#
###########
# Backend #
###########
backend default {
{{ conf_varnish_backend_default }}}
#############
# ACL PURGE #
#############
acl purge {
{{ conf_varnish_acl_purge }}}
#
# X-Forwarded-For
#
# See: https://www.varnish-cache.org/docs/2.1/faq/http.html
# % varnishlog | grep X-Forwarded-For
#
# We can have two scenarios actually:
#
# REQUEST -> Varnish -> Apache2 (Varnish inserts X-Forwarded-For)
# REQUEST -> HAPROXY -> Varnish -> Apache2 (HAPROXY inserts X-Forwarded-For)
#
# In case Varnish is first in the chain, insert own X-Forwarded-For.
# Boolean "conf_lbtier_enable", defined per node, tells us if we use HAPROXY.
#
################
# sub vcl_recv #
################
sub vcl_hash {
hash_data(req.http.host);
hash_data(req.url);
hash_data(req.http.X-Forwarded-Proto);
return(hash);
}
################
# sub vcl_recv #
################
sub vcl_recv {
{{ conf_varnish_vcl_recv }}}
#################
# sub vcl_fetch #
#################
sub vcl_fetch {
#set obj.grace = 5m;
set beresp.grace = 2m;
}
###############
# sub vcl_hit #
###############
sub vcl_hit {
if (req.request == "PURGE") {
purge;
error 200 "Purged.";
}
}
################
# sub vcl_miss #
################
sub vcl_miss {
if (req.request == "PURGE") {
purge;
error 200 "Not in cache.";
}
}
################
# sub vcl_pass #
################
sub vcl_pass {
if (req.request == "PURGE") {
error 502 "PURGE on a passed object";
}
}