Skip to content

Commit 05b0b65

Browse files
committed
Set a hardcoded cache-control for /content/storage
1 parent c2f2777 commit 05b0b65

3 files changed

Lines changed: 51 additions & 2 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# location {} settings for /content caching
2+
# used by files in this directory, via `include` directive
3+
4+
# ignore cache-control from upstream so this value is authoritative
5+
proxy_hide_header Cache-Control;
6+
7+
# content is md5-addressed, so cache aggressively for successful responses
8+
add_header Cache-Control "public, max-age=31536000, immutable, no-transform";

docker/nginx/includes/content/develop-studio-content.conf

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,46 @@ location @production {
1717
proxy_pass https://studio-content.storage.googleapis.com;
1818
}
1919

20+
location @hotfixes_storage {
21+
include /etc/nginx/includes/content/_proxy.conf;
22+
include /etc/nginx/includes/content/_cache.conf;
23+
24+
# this is the magic that allows us to intercept errors and try the next location
25+
proxy_intercept_errors on;
26+
recursive_error_pages on;
27+
error_page 404 = @production_storage;
28+
29+
proxy_pass https://develop-studio-content.storage.googleapis.com;
30+
}
31+
32+
location @production_storage {
33+
include /etc/nginx/includes/content/_proxy.conf;
34+
include /etc/nginx/includes/content/_cache.conf;
35+
36+
proxy_pass https://studio-content.storage.googleapis.com;
37+
}
38+
2039
location @nowhere {
2140
return 404;
2241
}
2342

43+
# Note on try_files
44+
# -----------------
45+
# try_files will only use one named route, and it uses the last one. Although, we can't just pass
46+
# one named route, because it fails.
47+
48+
location ^~ /content/storage/ {
49+
# ensure that the /content/ prefix is stripped from the request
50+
rewrite ^/content/(.*)$ /$1 break;
51+
52+
# check staging bucket first, then fall back to production
53+
try_files @nowhere @hotfixes_storage;
54+
}
55+
2456
location /content/ {
2557
# ensure that the /content/ prefix is stripped from the request
2658
rewrite ^/content/(.*)$ /$1 break;
2759

2860
# check the emulator bucket first, then cloud development bucket, then fall back to production
29-
# try_files will only use one named route, and it uses the last one. Although, we can just
30-
# pass one named route, because it fails.
3161
try_files @nowhere @hotfixes;
3262
}

docker/nginx/includes/content/studio-content.conf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# DO NOT RENAME: this file is named after the primary bucket it proxies to
22

3+
location ^~ /content/storage/ {
4+
include /etc/nginx/includes/content/_proxy.conf;
5+
include /etc/nginx/includes/content/_cache.conf;
6+
7+
# ensure that the /content/ prefix is stripped from the request
8+
rewrite ^/content/(.*)$ /$1 break;
9+
10+
# just direct proxy to the bucket
11+
proxy_pass https://studio-content.storage.googleapis.com;
12+
}
13+
314
location /content/ {
415
include /etc/nginx/includes/content/_proxy.conf;
516

0 commit comments

Comments
 (0)