forked from fbrnc/Aoe_Static
-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.vcl
99 lines (90 loc) · 2.3 KB
/
default.vcl
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
backend default {
.host = "127.0.0.1";
.port = "80";
.first_byte_timeout = 300s;
}
/*
Like the default function, only that cookies don't prevent caching
*/
sub vcl_recv {
# if (req.http.Host != "varnish.demo.aoemedia.de") {
# return (pipe);
# }
if (req.http.x-forwarded-for) {
set req.http.X-Forwarded-For =
req.http.X-Forwarded-For ", " client.ip;
} else {
set req.http.X-Forwarded-For = client.ip;
}
if (req.request != "GET" &&
req.request != "HEAD" &&
req.request != "PUT" &&
req.request != "POST" &&
req.request != "TRACE" &&
req.request != "OPTIONS" &&
req.request != "DELETE") {
/* Non-RFC2616 or CONNECT which is weird. */
return (pipe);
}
# Some known-static file types
if (req.url ~ "^[^?]*\.(css|js|htc|xml|txt|swf|flv|pdf|gif|jpe?g|png|ico)$") {
# Pretent no cookie was passed
unset req.http.Cookie;
}
# Force lookup if the request is a no-cache request from the client.
if (req.http.Cache-Control ~ "no-cache") {
purge_url(req.url);
}
if (req.request != "GET" && req.request != "HEAD") {
/* We only deal with GET and HEAD by default */
return (pass);
}
if (req.http.Authorization) {
/* Not cacheable by default */
return (pass);
}
return (lookup);
}
/*
Remove cookies from backend response so this page can be cached
*/
sub vcl_fetch {
if (beresp.status == 302 || beresp.status == 301 || beresp.status == 418) {
return (pass);
}
if (beresp.http.aoestatic == "cache") {
remove beresp.http.Set-Cookie;
remove beresp.http.X-Cache;
remove beresp.http.Server;
remove beresp.http.Age;
remove beresp.http.Pragma;
set beresp.http.Cache-Control = "public";
set beresp.grace = 2m;
set beresp.http.X_AOESTATIC_FETCH = "Removed cookie in vcl_fetch";
} else {
set beresp.http.X_AOESTATIC_FETCH = "Nothing removed";
}
# Some known-static file types
if (req.url ~ "^[^?]*\.(css|js|htc|xml|txt|swf|flv|pdf|gif|jpe?g|png|ico)$") {
# Force caching
remove beresp.http.Pragma;
remove beresp.http.Set-Cookie;
set beresp.http.Cache-Control = "public";
}
if (!beresp.cacheable) {
return (pass);
}
return (deliver);
}
/*
Adding debugging information
*/
sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT";
set resp.http.Server = "Varnish (HIT)";
} else {
set resp.http.X-Cache = "MISS";
set resp.http.Server = "Varnish (MISS)";
}
}