9 # ACL for IPs that are allowed to PURGE data from the cache
15 # Redirect HTTP to HTTPS
16 if (std.port(server.ip) != 443) {
17 set req.http.x-redir = "https://" + req.http.host + req.url;
18 return (synth(750, ""));
22 if (req.http.Range ~ "bytes=") {
23 set req.http.x-range = req.http.Range;
26 # Pipe if WebSockets request is coming through
27 if (req.http.upgrade ~ "(?i)websocket") {
31 # Allow purging of the cache
32 if (req.method == "PURGE") {
33 if (!client.ip ~ purge) {
34 return(synth(405,"Not allowed."));
39 # Pleroma MediaProxy - strip headers that will affect caching
40 if (req.url ~ "^/proxy/") {
41 unset req.http.Cookie;
42 unset req.http.Authorization;
43 unset req.http.Accept;
47 # Strip headers that will affect caching from all other static content
48 # This also permits caching of individual toots and AP Activities
49 if ((req.url ~ "^/(media|static)/") ||
50 (req.url ~ "(?i)\.(html|js|css|jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|mp4|ogg|webm|svg|swf|ttf|pdf|woff|woff2)$"))
52 unset req.http.Cookie;
53 unset req.http.Authorization;
58 sub vcl_backend_response {
60 if (beresp.http.content-type ~ "(text|text/css|application/x-javascript|application/javascript)") {
61 set beresp.do_gzip = true;
65 if (bereq.http.x-range ~ "bytes=" && beresp.status == 206) {
67 set beresp.http.CR = beresp.http.content-range;
70 # Don't cache objects that require authentication
71 if (beresp.http.Authorization && !beresp.http.Cache-Control ~ "public") {
72 set beresp.uncacheable = true;
76 # Default object caching of 86400s;
77 set beresp.ttl = 86400s;
78 # Allow serving cached content for 6h in case backend goes down
79 set beresp.grace = 6h;
81 # Do not cache 5xx responses
82 if (beresp.status == 500 || beresp.status == 502 || beresp.status == 503 || beresp.status == 504) {
83 set beresp.uncacheable = true;
87 # Do not cache redirects and errors
88 if ((beresp.status >= 300) && (beresp.status < 500)) {
89 set beresp.uncacheable = true;
94 # Pleroma MediaProxy internally sets headers properly
95 if (bereq.url ~ "^/proxy/") {
99 # Strip cache-restricting headers from Pleroma on static content that we want to cache
100 if (bereq.url ~ "(?i)\.(js|css|jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|mp4|ogg|webm|svg|swf|ttf|pdf|woff|woff2)$")
102 unset beresp.http.set-cookie;
103 unset beresp.http.Cache-Control;
104 unset beresp.http.x-request-id;
105 set beresp.http.Cache-Control = "public, max-age=86400";
109 # The synthetic response for 301 redirects
111 if (resp.status == 750) {
112 set resp.status = 301;
113 set resp.http.Location = req.http.x-redir;
118 # Ensure WebSockets through the pipe do not close prematurely
120 if (req.http.upgrade) {
121 set bereq.http.upgrade = req.http.upgrade;
122 set bereq.http.connection = req.http.connection;
128 if (req.http.x-range ~ "bytes=") {
129 hash_data(req.http.x-range);
130 unset req.http.Range;
134 sub vcl_backend_fetch {
136 if (bereq.http.x-range) {
137 set bereq.http.Range = bereq.http.x-range;
144 set resp.http.Content-Range = resp.http.CR;