-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcloudways.vcl
198 lines (186 loc) · 6.64 KB
/
cloudways.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
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#Please do not perform any modification here #
vcl 4.0;
include "/etc/varnish/backends.vcl";
include "/etc/varnish/vars.vcl";
import std;
acl purge {
"localhost";
"127.0.0.1";
}
sub vcl_hit {
if (req.method == "PURGE") {
return(synth(200,"OK"));
if (req.http.X-Application ~ "(?i)magento" && req.http.X-Version ~ "^2") {
if (obj.ttl >= 0s) {
# Hit within TTL period
return (deliver);
}
if (std.healthy(req.backend_hint)) {
if (obj.ttl + 300s > 0s) {
# Hit after TTL expiration, but within grace period
set req.http.grace = "normal (healthy server)";
return (deliver);
} else {
# Hit after TTL and grace expiration
return (restart);
}
} else {
# server is not healthy, retrieve from cache
set req.http.grace = "unlimited (unhealthy server)";
return (deliver);
}
}
}
}
sub vcl_miss {
if (req.method == "PURGE") {
return(synth(404,"Not cached"));
}
}
sub vcl_pipe {
if (req.http.X-Application ~ "(?i)magento") {
if (req.http.X-Version !~ "^2") {
unset bereq.http.X-Turpentine-Secret-Handshake;
set bereq.http.Connection = "close";
}
}
}
#Recieve
sub vcl_recv {
if (req.restarts == 0) {
if (req.http.x-forwarded-for) {
set req.http.X-Forwarded-For = req.http.X-Real-IP;
}
}
if (req.http.X-Application ~ "(?i)varnishpass") {
return (pipe);
}
include "/etc/varnish/https.vcl";
include "/etc/varnish/additional_vcls/recv.vcl";
if (req.http.X-Application ~ "(?i)wordpress") {
include "/etc/varnish/recv/wordpress.vcl";
} else if (req.http.X-Application ~ "(?i)drupal") {
include "/etc/varnish/recv/drupal.vcl";
} else if (req.http.X-Application ~ "(?i)woocommerce") {
include "/etc/varnish/recv/woocommerce.vcl";
} else if (req.http.X-Application ~ "(?i)magento") {
if (req.http.X-Version) {
if (req.http.X-Version ~ "^2") {
include "/etc/varnish/recv/magento2.vcl";
} else {
include "/etc/varnish/recv/magento.vcl";
}
} else {
include "/etc/varnish/recv/magento.vcl";
}
} else if (req.http.X-Application ~ "(?i)mediawiki") {
include "/etc/varnish/recv/mediawiki.vcl";
} else if (req.http.X-Application ~ "(?i)joomla") {
include "/etc/varnish/recv/joomla.vcl";
} else if (req.http.X-Application ~ "(?i)phpstack") {
include "/etc/varnish/recv/phpstack.vcl";
} else if (req.http.X-Application ~ "(?i)koken") {
return (pipe);
} else {
include "/etc/varnish/recv/default.vcl";
}
}
## backend_response (replacement of fetch)
sub vcl_backend_response {
if ( beresp.status == 500 ||
beresp.status == 502 ||
beresp.status == 503 ||
beresp.status == 504 ||
beresp.status == 400 ||
beresp.status == 404 ||
beresp.status == 403 ){
set beresp.uncacheable = true;
}
include "/etc/varnish/additional_vcls/resp.vcl";
if (bereq.http.X-Application ~ "(?i)wordpress") {
include "/etc/varnish/backend_response/wordpress.vcl";
} else if (bereq.http.X-Application ~ "(?i)drupal") {
include "/etc/varnish/backend_response/drupal.vcl";
} else if (bereq.http.X-Application ~ "(?i)woocommerce") {
include "/etc/varnish/backend_response/woocommerce.vcl";
} else if (bereq.http.X-Application ~ "(?i)magento") {
if (bereq.http.X-Version) {
if (bereq.http.X-Version ~ "^2") {
include "/etc/varnish/backend_response/magento2.vcl";
} else {
include "/etc/varnish/backend_response/magento.vcl";
}
} else {
include "/etc/varnish/backend_response/magento.vcl";
}
} else if (bereq.http.X-Application ~ "(?i)mediawiki") {
include "/etc/varnish/backend_response/mediawiki.vcl";
} else if (bereq.http.X-Application ~ "(?i)joomla") {
include "/etc/varnish/backend_response/joomla.vcl";
} else if (bereq.http.X-Application ~ "(?i)phpstack") {
include "/etc/varnish/backend_response/phpstack.vcl";
} else {
include "/etc/varnish/backend_response/default.vcl";
}
}
## Deliver
sub vcl_deliver {
if (req.http.X-Application !~ "(?i)magento" && req.http.X-Version !~ "^2") {
unset resp.http.X-Varnish;
}
unset resp.http.Via;
unset resp.http.X-Powered-By;
if (req.http.X-Application ~ "(?i)wordpress") {
include "/etc/varnish/deliver/wordpress.vcl";
} else if (req.http.X-Application ~ "(?i)drupal") {
include "/etc/varnish/deliver/drupal.vcl";
} else if (req.http.X-Application ~ "(?i)woocommerce") {
include "/etc/varnish/deliver/woocommerce.vcl";
} else if (req.http.X-Application ~ "(?i)magento") {
if (req.http.X-Version) {
if (req.http.X-Version ~ "^2") {
include "/etc/varnish/deliver/magento2.vcl";
} else {
include "/etc/varnish/deliver/magento.vcl";
}
} else {
include "/etc/varnish/deliver/magento.vcl";
}
} else if (req.http.X-Application ~ "(?i)mediawiki") {
include "/etc/varnish/deliver/mediawiki.vcl";
} else if (req.http.X-Application ~ "(?i)joomla") {
include "/etc/varnish/deliver/joomla.vcl";
} else if (req.http.X-Application ~ "(?i)phpstack") {
include "/etc/varnish/deliver/phpstack.vcl";
} else {
include "/etc/varnish/deliver/default.vcl";
}
}
sub vcl_hash {
if (req.http.X-Application ~ "(?i)magento") {
if (req.http.X-Version) {
if (req.http.X-Version ~ "^2") {
include "/etc/varnish/hash/magento2.vcl";
} else {
include "/etc/varnish/hash/magento.vcl";
}
}
}
if (req.http.X-Forwarded-Proto) {
hash_data(req.http.X-Forwarded-Proto);
}
include "/etc/varnish/hash/geoip.vcl";
}
sub vcl_synth {
set resp.http.Content-Type = "text/html; charset=utf-8";
set resp.http.Retry-After = "5";
return (deliver);
}
sub process_graphql_headers {
if (req.http.Store) {
hash_data(req.http.Store);
}
if (req.http.Content-Currency) {
hash_data(req.http.Content-Currency);
}
}