-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathproject.vcl
More file actions
152 lines (132 loc) · 4.52 KB
/
project.vcl
File metadata and controls
152 lines (132 loc) · 4.52 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#
# Fastly (Varnish) configuration for project.webplatform.org
#
# Service: project, v 28 (18)
#
# Backend configs:
# - Max connections: 500
# - Error treshold: 5
# - Connection (ms): 3000
# - First byte (ms): 15000
# - Between bytes (ms): 10000
#
# Assuming it is using Varnish 2.1.5 syntax
#
# Ref:
# - https://www.varnish-cache.org/docs/2.1/tutorial/vcl.html
# - https://www.varnish-software.com/static/book/VCL_functions.html
# - http://docs.fastly.com/guides/22958207/27123847
# - http://docs.fastly.com/guides/22958207/23206371
# - https://www.varnish-cache.org/docs/2.1/tutorial/increasing_your_hitrate.html
# - https://fastly.zendesk.com/entries/23206371
#
# Doc: Called at the beginning of a request, after the complete request
# has been received and parsed. Its purpose is to
# decide whether or not to serve the request, how to
# do it, and, if applicable, which backend to use.
sub vcl_recv {
#FASTLY recv
set client.identity = req.http.Fastly-Client-IP;
#
# Handle grace periods for where we will serve a stale response
# source: https://github.com/python/psf-fastly/blob/master/vcl/pypi.vcl
if (!req.backend.healthy) {
# The backend is unhealthy which means we want to serve the stale
# response long enough (hopefully) for us to fix the problem.
set req.grace = 24h;
# The backend is unhealthy which means we want to serve responses as
# if the user was not logged in. This means they will be eligible
# for the cached pages.
remove req.http.Authenticate;
remove req.http.Authorization;
remove req.http.Cookie;
}
else {
# Avoid a request pileup by serving stale content if required.
set req.grace = 15s;
}
# Remove ALL cookies to the backend
# except the ones MediaWiki cares about
if(req.url ~ "login") {
# Do not tamper cookies
} else {
if (req.http.Cookie) {
set req.http.Cookie = ";" req.http.Cookie;
set req.http.Cookie = regsuball(req.http.Cookie, "; +", ";");
set req.http.Cookie = regsuball(req.http.Cookie, ";(THEBUGGENIE|tbg3_username|tbg4_username|tbg3_password|tbg4_password)=", "; \1=");
set req.http.Cookie = regsuball(req.http.Cookie, ";[^ ][^;]*", "");
set req.http.Cookie = regsuball(req.http.Cookie, "^[; ]+|[; ]+$", "");
if (req.http.Cookie == "") {
remove req.http.Cookie;
}
}
}
## Fastly BOILERPLATE ========
if (req.request != "HEAD" && req.request != "GET" && req.request != "PURGE") {
return(pass);
}
return(lookup);
## /Fastly BOILERPLATE =======
}
# Doc: Called after a document has been successfully retrieved from the backend
sub vcl_fetch {
#FASTLY fetch
# Set the maximum grace period on an object
set beresp.grace = 24h;
# Debug notes
if(!beresp.http.X-Cache-Note) {
set beresp.http.X-Cache-Note = "Debugging notes: ";
}
## Fastly BOILERPLATE ========
if ((beresp.status == 500 || beresp.status == 503) && req.restarts < 1 && (req.request == "GET" || req.request == "HEAD")) {
restart;
}
if(req.restarts > 0 ) {
set beresp.http.Fastly-Restarts = req.restarts;
}
if (beresp.http.Set-Cookie) {
set req.http.Fastly-Cachetype = "SETCOOKIE";
return (pass);
}
if (beresp.http.Cache-Control ~ "private") {
set req.http.Fastly-Cachetype = "PRIVATE";
return (pass);
}
if (beresp.status == 500 || beresp.status == 503) {
set req.http.Fastly-Cachetype = "ERROR";
set beresp.ttl = 1s;
set beresp.grace = 5s;
return (deliver);
}
if (beresp.http.Expires || beresp.http.Surrogate-Control ~ "max-age" || beresp.http.Cache-Control ~"(s-maxage|max-age)") {
# keep the ttl here
} else {
# apply the default ttl
set beresp.ttl = 3600s;
}
return(deliver);
## /Fastly BOILERPLATE =======
}
sub vcl_deliver {
#FASTLY deliver
# Always send this instead of using meta tags in markup
if ( resp.http.Content-Type ~ "html" ) {
set resp.http.X-UA-Compatible = "IE=edge,chrome=1";
}
# The (!req.http.Fastly-FF) is to differentiate between
# edge to the sheild nodes. Shield nodes has a Fastly-FF
# header added internally.
if ((!req.http.Fastly-FF) && (!req.http.Fastly-Debug)) {
remove resp.http.X-Cache-Note;
remove resp.http.X-Backend-Key;
remove resp.http.Server;
remove resp.http.Via;
remove resp.http.X-Served-By;
remove resp.http.X-Cache;
remove resp.http.X-Cache-Hits;
remove resp.http.X-Timer;
}
## Fastly BOILERPLATE ========
return(deliver);
## /Fastly BOILERPLATE =======
}