2013-09-22 23:31:13
CKAN data.gov.au
1
# This is a basic VCL configuration file for varnish. See the vcl(7)
2
# man page for details on VCL syntax and semantics.
3
#
4
# Default backend definition. Set this to point to your content
5
# server.
6
#
7
backend default {
8
.host = "127.0.0.1";
9
.port = "8080";
10
}
2013-12-20 00:32:03
root
11
12
sub vcl_fetch {
13
set beresp.grace = 1h;
14
2013-09-22 23:31:13
CKAN data.gov.au
15
if (beresp.http.content-type ~ "(text|application)") {
16
set beresp.do_gzip = true;
17
}
2013-12-20 00:32:03
root
18
if (req.url ~ "\.(png|gif|jpg|jpeg|swf|css|js|woff|eot)$") {
19
unset beresp.http.set-cookie;
20
}
21
}
22
sub vcl_recv {
23
if (req.url ~ "^/_tracking") {
2013-09-22 23:31:13
CKAN data.gov.au
24
return (pass);
25
}
2013-12-20 00:32:03
root
26
if (req.url ~ "\.(png|gif|jpg|jpeg|swf|css|js|woff|eot)$") {
27
return(lookup);
28
}
29
if (req.http.Cookie) {
30
set req.http.Cookie = regsuball(req.http.Cookie, "(^|; ) *__utm.=[^;]+;? *", "\1"); # removes all cookies named __utm? (utma, utmb...) - tracking thing
31
32
if (req.http.Cookie == "") {
33
remove req.http.Cookie;
34
}
35
}
36
}
37
sub vcl_hash {
38
# http://serverfault.com/questions/112531/ignoring-get-parameters-in-varnish-vcl
39
set req.url = regsub(req.url, "/../|/.._../", "/");
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
return (hash);
47
}
48
sub vcl_deliver {
49
if (!resp.http.Vary) {
50
set resp.http.Vary = "Accept-Encoding";
51
} else if (resp.http.Vary !~ "(?i)Accept-Encoding") {
52
set resp.http.Vary = resp.http.Vary + ",Accept-Encoding";
53
}
54
if (obj.hits > 0) {
2013-09-22 23:31:13
CKAN data.gov.au
55
set resp.http.X-Cache = "HIT";
56
} else {
2013-12-20 00:32:03
root
57
set resp.http.X-Cache = "MISS";
58
}
59
}
60
61
#
62
# Below is a commented-out copy of the default VCL logic. If you
63
# redefine any of these subroutines, the built-in logic will be
64
# appended to your code.
65
# sub vcl_recv {
66
# if (req.restarts == 0) {
67
# if (req.http.x-forwarded-for) {
68
# set req.http.X-Forwarded-For =
69
# req.http.X-Forwarded-For + ", " + client.ip;
70
# } else {
71
# set req.http.X-Forwarded-For = client.ip;
72
# }
73
# }
74
# if (req.request != "GET" &&
75
# req.request != "HEAD" &&
76
# req.request != "PUT" &&
77
# req.request != "POST" &&
78
# req.request != "TRACE" &&
79
# req.request != "OPTIONS" &&
80
# req.request != "DELETE") {
81
# /* Non-RFC2616 or CONNECT which is weird. */
82
# return (pipe);
83
# }
84
# if (req.request != "GET" && req.request != "HEAD") {
85
# /* We only deal with GET and HEAD by default */
86
# return (pass);
87
# }
88
# if (req.http.Authorization || req.http.Cookie) {
89
# /* Not cacheable by default */
90
# return (pass);
91
# }
2013-09-22 23:31:13
CKAN data.gov.au
92
# return (lookup);
2013-12-20 00:32:03
root
93
# }
94
#
2013-09-22 23:31:13
CKAN data.gov.au
95
# sub vcl_pipe {
2013-09-27 07:51:29
CKAN data.gov.au
96
# # Note that only the first request to the backend will have
2013-12-20 00:32:03
root
97
# # X-Forwarded-For set. If you use X-Forwarded-For and want to
98
# # have it set for all requests, make sure to have:
2013-09-22 23:31:13
CKAN data.gov.au
99
# # set bereq.http.connection = "close";
2013-12-20 00:32:03
root
100
# # here. It is not set by default as it might break some broken web
101
# # applications, like IIS with NTLM authentication.
102
# return (pipe);
103
# }
104
#
2013-09-22 23:31:13
CKAN data.gov.au
105
# sub vcl_pass {
2013-12-20 00:32:03
root
106
# return (pass);
107
# }
108
#
2013-09-22 23:31:13
CKAN data.gov.au
109
# sub vcl_hash {
2013-09-25 09:26:40
CKAN data.gov.au
110
# hash_data(req.url);
111
# if (req.http.host) {
2013-12-20 00:32:03
root
112
# hash_data(req.http.host);
2013-09-25 09:26:40
CKAN data.gov.au
113
# } else {
114
# hash_data(server.ip);
115
# }
116
# return (hash);
117
# }
118
#
2013-12-20 00:32:03
root
119
# sub vcl_hit {
120
# return (deliver);
121
# }
2013-09-25 09:26:40
CKAN data.gov.au
122
#
2013-09-22 23:31:13
CKAN data.gov.au
123
# sub vcl_miss {
124
# return (fetch);
125
# }
126
#
127
# sub vcl_fetch {
128
# if (beresp.ttl <= 0s ||
2013-12-20 00:32:03
root
129
# beresp.http.Set-Cookie ||
130
# beresp.http.Vary == "*") {
131
# /*
132
# * Mark as "Hit-For-Pass" for the next 2 minutes
133
# */
134
# set beresp.ttl = 120 s;
135
# return (hit_for_pass);
136
# }
137
# return (deliver);
2013-09-22 23:31:13
CKAN data.gov.au
138
# }
2013-12-20 00:32:03
root
139
#
140
# sub vcl_deliver {
141
# return (deliver);
142
# }
143
#
144
# sub vcl_error {
145
# set obj.http.Content-Type = "text/html; charset=utf-8";
146
# set obj.http.Retry-After = "5";
147
# synthetic {"
148
# <?xml version="1.0" encoding="utf-8"?>
149
# <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
150
# "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
151
# <html>
2013-09-22 23:31:13
CKAN data.gov.au
152
# <head>
153
# <title>"} + obj.status + " " + obj.response + {"</title>
154
# </head>
155
# <body>
156
# <h1>Error "} + obj.status + " " + obj.response + {"</h1>
157
# <p>"} + obj.response + {"</p>
158
# <h3>Guru Meditation:</h3>
159
# <p>XID: "} + req.xid + {"</p>
160
# <hr>
161
# <p>Varnish cache server</p>
162
# </body>
163
# </html>
164
# "};
165
# return (deliver);
166
# }
167
#
168
# sub vcl_init {
169
# return (ok);
170
# }
171
#
172
# sub vcl_fini {
173
# return (ok);
174
# }
175