Skip to content

Commit

Permalink
feat(infra): nginx caching of static assets (#4609)
Browse files Browse the repository at this point in the history
* feat(infra): nginx caching of static assets
  • Loading branch information
fredboyle authored Mar 24, 2021
1 parent a47a4ca commit 0558193
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
19 changes: 19 additions & 0 deletions config/nginx.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ http {
# Must read the body in 5 seconds.
client_body_timeout <%= ENV['NGINX_CLIENT_BODY_TIMEOUT'] || 5 %>;

# CACHING
proxy_cache_path cache/nginx levels=1:2 keys_zone=STATIC:10m inactive=7d use_temp_path=off;

# handle SNI
proxy_ssl_server_name on;
# resolver needs to be set because we're using dynamic proxy_pass
Expand All @@ -44,6 +47,11 @@ http {

port_in_redirect off;

gzip on;
gzip_proxied any;
gzip_comp_level 4;
gzip_types text/css application/javascript image/svg+xml;

# Redirect all non-SSL requests
if ($http_x_forwarded_proto != 'https') {
return 301 https://$host$request_uri;
Expand All @@ -64,6 +72,11 @@ http {

port_in_redirect off;

gzip on;
gzip_proxied any;
gzip_comp_level 4;
gzip_types text/css application/javascript image/svg+xml;

# Redirect all non-SSL requests
if ($http_x_forwarded_proto != 'https') {
return 301 https://$host$request_uri;
Expand Down Expand Up @@ -101,6 +114,12 @@ http {

root /app/.www;

location /assets {
proxy_cache STATIC;
proxy_ignore_headers Cache-Control;
proxy_cache_valid 60m;
}

location / {
index index.html index.htm;
}
Expand Down
4 changes: 4 additions & 0 deletions heroku-start.sh
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# Initialize cache directory.
mkdir -p cache/nginx
echo 'script=heroku-start at=cache-initialized'
#
bin/start-nginx-solo

0 comments on commit 0558193

Please sign in to comment.