-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser-side.vcl
124 lines (103 loc) · 2.75 KB
/
user-side.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#
# CDN frontend/user side varnish
#
vcl 4.0;
# Default backend definition. Set this to point to your content server.
backend backendvarnish1 {
.host = "192.168.0.140";
.port = "6081";
.probe = {
.url = "/varnishping";
.interval = 10s;
.timeout = 2s;
.window = 5;
.threshold = 3;
}
}
backend backendvarnish2 {
.host = "192.168.0.140";
.port = "6081";
.probe = {
.url = "/varnishping";
.interval = 10s;
.timeout = 2s;
.window = 5;
.threshold = 3;
}
}
backend backendvarnish3 {
.host = "192.168.0.140";
.port = "6081";
.probe = {
.url = "/varnishping";
.interval = 10s;
.timeout = 2s;
.window = 5;
.threshold = 3;
}
}
backend localnginx {
.host = "127.0.0.1";
.port = "81";
.probe = {
.url = "/varnishping";
.interval = 10s;
.timeout = 2s;
.window = 5;
.threshold = 3;
}
}
import directors;
sub vcl_init {
# this picks from a group of backend varnishes based on hash of request urls
new hashdir = directors.hash();
hashdir.add_backend(backendvarnish1,1);
hashdir.add_backend(backendvarnish2,1);
hashdir.add_backend(backendvarnish3,1);
# this will try a backend varnish or fall back to nginx local which will fetch from the real server
# currently though we are just forcing to nginx on localhost if the chosen server in the above hash group is down
# new vdir = directors.fallback();
# vdir.add_backend(somegenericvarnish);
# vdir.add_backend(localnginx);
}
sub vcl_recv {
if (req.restarts == 0) {
# try fetching from the hashed backend group
set req.backend_hint = hashdir.backend(req.url);
} else {
# try fetching with nginx if we restarted due to an error
# set req.backend_hint = vdir.backend();
set req.backend_hint = localnginx;
}
unset req.http.cookie;
return (hash);
}
sub vcl_backend_response {
# these should have been done by backend varnish
# but in case we fetched via nginx...
unset beresp.http.cache-control;
unset beresp.http.expires;
set beresp.ttl = 1h;
set beresp.grace = 6h;
}
sub vcl_deliver {
# try once more in case the hash servers are down
if ( req.restarts == 0 &&
resp.status != 200 && resp.status != 403 && resp.status != 404 &&
resp.status != 301 && resp.status != 302 && resp.status != 307 &&
resp.status != 410) {
return(restart);
}
set resp.http.frontendvarnish = "lol";
if (obj.hits > 0) {
set resp.http.j-front-cache = "hit";
} else {
set resp.http.j-front-cache = "miss";
}
}
sub vcl_hit {
return(deliver);
}
sub vcl_miss {
return(fetch);
}