-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathopenstreetmap4.vcl
83 lines (61 loc) · 1.51 KB
/
openstreetmap4.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
# VCL script for varnish 4
vcl 4.0;
backend default {
.host = "127.0.0.1";
.port = "80";
}
backend a_tile {
.host = "151.101.2.217";
.port = "80";
}
backend b_tile {
.host = "151.101.66.217";
.port = "80";
}
backend c_tile {
.host = "151.101.130.217";
.port = "80";
}
sub vcl_recv {
if (req.http.host ~ "^a.tile") {
set req.http.host = "a.tile.openstreetmap.org";
set req.backend_hint = a_tile;
} else if (req.http.host ~ "^b.tile") {
set req.http.host = "b.tile.openstreetmap.org";
set req.backend_hint = b_tile;
} else if (req.http.host ~ "^c.tile") {
set req.http.host = "c.tile.openstreetmap.org";
set req.backend_hint = c_tile;
} else if (req.http.host ~ "^a.map") {
set req.backend_hint = a_tile;
} else if (req.http.host ~ "^b.map") {
set req.backend_hint = b_tile;
} else if (req.http.host ~ "^c.map") {
set req.backend_hint = c_tile;
}
unset req.http.cookie;
// Cache everything
if (req.method == "GET") {
return (hash);
}
}
sub vcl_backend_response {
// Cache tiles for 3 weeks
set beresp.ttl = 3w;
// Remove all cookies
unset beresp.http.set-cookie;
unset beresp.http.cookie;
}
sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Cache_v = "HIT";
} else {
set resp.http.X-Cache_v = "MISS";
}
}
sub vcl_hash {
// Cache using only url as a hash.
// This means if a.tile/1/1/1/tile.png is accessed, b.tile/1/1/1/tile.png will also be fetch from cache
hash_data(req.url);
return (lookup);
}