-
Notifications
You must be signed in to change notification settings - Fork 2
/
varnish.vcl
72 lines (61 loc) · 1.63 KB
/
varnish.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
vcl 4.0;
backend default {
.host = "localhost";
.port = "5000";
}
sub vcl_recv {
if (req.restarts == 0) {
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.http.Accept-Encoding) {
if (req.url ~ "\.(ts|mp4|m4s|m4a)$") {
unset req.http.Accept-Encoding;
} elsif (req.http.Accept-Encoding ~ "gzip") {
set req.http.Accept-Encoding = "gzip";
} elsif (req.http.Accept-Encoding ~ "deflate" && req.http.user-agent !~ "MSIE") {
set req.http.Accept-Encoding = "deflate";
} else {
unset req.http.Accept-Encoding;
}
}
if (req.method == "GET") {
if (req.url ~ "\.m3u8$") {
return(pass);
} else {
return(hash);
}
}
if (req.method != "GET" && req.method != "HEAD") {
return(pipe);
}
return(hash);
}
sub vcl_backend_response {
set beresp.grace = 600s;
if (beresp.status >= 500) {
set beresp.ttl = 0s;
} else {
if (bereq.url ~ "\.m3u8$") {
set beresp.ttl = 1s;
} else {
set beresp.ttl = 30s;
}
}
set beresp.http.X-Cacheable = "YES";
unset beresp.http.set-cookie;
return(deliver);
}
sub vcl_deliver {
set resp.http.X-Served-By = server.hostname;
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT";
set resp.http.X-Cache-Hits = obj.hits;
} else {
set resp.http.X-Cache = "MISS";
}
return(deliver);
}