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
// VARNISH_SPHINX_TOKEN_42 — unique token for E2E assertions
vcl 4.1;
import std;
import directors;
import std as standard;
include "backends.vcl";
include "/etc/varnish/language.vcl";
// VARNISH_SPHINX_TOKEN_BACKEND_01
backend backend_default {
.host = "127.0.0.1";
.port = "8080";
.host_header = "example.com";
.connect_timeout = 1s;
.first_byte_timeout = 60s;
.between_bytes_timeout = 60s;
.max_connections = 100;
.probe = probe_health;
}
// VARNISH_SPHINX_TOKEN_PROBE_01
probe probe_health {
.url = "/healthz";
.expected_response = 200;
.timeout = 2s;
.interval = 5s;
.window = 8;
.threshold = 3;
}
// VARNISH_SPHINX_TOKEN_ACL_01
acl acl_localnetwork {
"localhost";
"192.0.2.0"/24;
"10.0.0.0"/8;
! "192.0.2.23";
}
// VARNISH_SPHINX_TOKEN_SUB_01
sub pipe_if_local {
if (client.ip ~ acl_localnetwork) {
return (pipe);
}
}
// VARNISH_SPHINX_TOKEN_BUILTIN_SUB_01
sub vcl_recv {
call pipe_if_local;
if (req.url == "/healthz") {
return (synth(200));
}
if (req.http.host ~ "^(www\.)?example\.com$") {
set req.backend_hint = backend_default;
}
if (client.ip ~ acl_localnetwork) {
std.log("Request from local network");
}
return (hash);
}
// VARNISH_SPHINX_TOKEN_BUILTIN_SUB_02
sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
standard.log("served response");
return (deliver);
}
// VARNISH_SPHINX_TOKEN_INIT_01
sub vcl_init {
new cluster_director = directors.round_robin();
cluster_director.add_backend(backend_default);
return (ok);
}
// VARNISH_SPHINX_TOKEN_UNUSED_01 unused b1
backend b1 { .host = "10.0.0.1"; }
unused b1;
backend default none;