Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docker/nginx/includes/content/_cache.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# location {} settings for /content caching
# used by files in this directory, via `include` directive

# ignore cache-control from upstream so this value is authoritative
proxy_hide_header Cache-Control;

# content is md5-addressed, so cache aggressively for successful responses
add_header Cache-Control "public, max-age=31536000, immutable, no-transform";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: Factoring the shared cache policy into a standalone include is clean DRY — one place to update if the directive set changes, and the comments explaining why each directive exists (immutable because URLs are hash-addressed, no-transform for MD5 integrity) are exactly the right level of documentation.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm with that guy ^

34 changes: 32 additions & 2 deletions docker/nginx/includes/content/develop-studio-content.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,46 @@ location @production {
proxy_pass https://studio-content.storage.googleapis.com;
}

location @hotfixes_storage {
include /etc/nginx/includes/content/_proxy.conf;
include /etc/nginx/includes/content/_cache.conf;

# this is the magic that allows us to intercept errors and try the next location
proxy_intercept_errors on;
recursive_error_pages on;
error_page 404 = @production_storage;

proxy_pass https://develop-studio-content.storage.googleapis.com;
}

location @production_storage {
include /etc/nginx/includes/content/_proxy.conf;
include /etc/nginx/includes/content/_cache.conf;

proxy_pass https://studio-content.storage.googleapis.com;
}

location @nowhere {
return 404;
}

# Note on try_files
# -----------------
# try_files will only use one named route, and it uses the last one. Although, we can't just pass
# one named route, because it fails.

location ^~ /content/storage/ {
# ensure that the /content/ prefix is stripped from the request
rewrite ^/content/(.*)$ /$1 break;

# check staging bucket first, then fall back to production
try_files @nowhere @hotfixes_storage;
}

Comment thread
DXCanas marked this conversation as resolved.
location /content/ {
# ensure that the /content/ prefix is stripped from the request
rewrite ^/content/(.*)$ /$1 break;

# check the emulator bucket first, then cloud development bucket, then fall back to production
# try_files will only use one named route, and it uses the last one. Although, we can just
# pass one named route, because it fails.
try_files @nowhere @hotfixes;
}
11 changes: 11 additions & 0 deletions docker/nginx/includes/content/studio-content.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# DO NOT RENAME: this file is named after the primary bucket it proxies to

location ^~ /content/storage/ {
include /etc/nginx/includes/content/_proxy.conf;
include /etc/nginx/includes/content/_cache.conf;
Comment thread
bjester marked this conversation as resolved.

# ensure that the /content/ prefix is stripped from the request
rewrite ^/content/(.*)$ /$1 break;

# just direct proxy to the bucket
proxy_pass https://studio-content.storage.googleapis.com;
}

location /content/ {
include /etc/nginx/includes/content/_proxy.conf;

Expand Down
Loading