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, ""));
21 # Pipe if WebSockets request is coming through
22 if (req.http.upgrade ~ "(?i)websocket") {
26 # Allow purging of the cache
27 if (req.method == "PURGE") {
28 if (!client.ip ~ purge) {
29 return(synth(405,"Not allowed."));
34 # Pleroma MediaProxy - strip headers that will affect caching
35 if (req.url ~ "^/proxy/") {
36 unset req.http.Cookie;
37 unset req.http.Authorization;
38 unset req.http.Accept;
42 # Hack to enable a Terms of Service page missing from Pleroma
43 if (req.url ~ "^/about/more$") {
44 set req.http.x-redir = "https://" + req.http.host + "/static/terms-of-service.html";
45 return (synth(750, ""));
48 # Strip headers that will affect caching from all other static content
49 # This also permits caching of individual toots and AP Activities
50 if ((req.url ~ "^/(media|notice|objects|static)/") ||
51 (req.url ~ "(?i)\.(html|js|css|jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|svg|swf|ttf|pdf|woff|woff2)$"))
53 unset req.http.Cookie;
54 unset req.http.Authorization;
58 # Everything else should just be piped to Pleroma
62 sub vcl_backend_response {
64 if (beresp.http.content-type ~ "(text|text/css|application/x-javascript|application/javascript)") {
65 set beresp.do_gzip = true;
69 unset beresp.http.etag;
71 # Don't cache objects that require authentication
72 if (beresp.http.Authorization && !beresp.http.Cache-Control ~ "public") {
73 set beresp.uncacheable = true;
77 # Default object caching of 86400s;
78 set beresp.ttl = 86400s;
79 # Allow serving cached content for 6h in case backend goes down
80 set beresp.grace = 6h;
82 # Do not cache 5xx responses
83 if (beresp.status == 500 || beresp.status == 502 || beresp.status == 503 || beresp.status == 504) {
84 set beresp.uncacheable = true;
88 # Do not cache redirects and errors
89 if ((beresp.status >= 300) && (beresp.status < 500)) {
90 set beresp.uncacheable = true;
95 # Pleroma MediaProxy internally sets headers properly
96 if (bereq.url ~ "^/proxy/") {
100 # Strip cache-restricting headers from Pleroma on static content that we want to cache
101 # Also enable streaming of cached content to clients (no waiting for Varnish to complete backend fetch)
102 if ((bereq.url ~ "^/(notice|objects)/") ||
103 (bereq.url ~ "(?i)\.(js|css|jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|svg|swf|ttf|pdf|woff|woff2)$"))
105 unset beresp.http.set-cookie;
106 unset beresp.http.Cache-Control;
107 unset beresp.http.x-request-id;
108 set beresp.http.Cache-Control = "public, max-age=86400";
109 set beresp.do_stream = true;
113 # The synthetic response for 301 redirects
115 if (resp.status == 750) {
116 set resp.status = 301;
117 set resp.http.Location = req.http.x-redir;
122 # Ensure WebSockets through the pipe do not close prematurely
124 if (req.http.upgrade) {
125 set bereq.http.upgrade = req.http.upgrade;
126 set bereq.http.connection = req.http.connection;