Skip to content

Commit 0558193

Browse files
authored
feat(infra): nginx caching of static assets (#4609)
* feat(infra): nginx caching of static assets
1 parent a47a4ca commit 0558193

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

config/nginx.conf.erb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ http {
2626
# Must read the body in 5 seconds.
2727
client_body_timeout <%= ENV['NGINX_CLIENT_BODY_TIMEOUT'] || 5 %>;
2828

29+
# CACHING
30+
proxy_cache_path cache/nginx levels=1:2 keys_zone=STATIC:10m inactive=7d use_temp_path=off;
31+
2932
# handle SNI
3033
proxy_ssl_server_name on;
3134
# resolver needs to be set because we're using dynamic proxy_pass
@@ -44,6 +47,11 @@ http {
4447

4548
port_in_redirect off;
4649

50+
gzip on;
51+
gzip_proxied any;
52+
gzip_comp_level 4;
53+
gzip_types text/css application/javascript image/svg+xml;
54+
4755
# Redirect all non-SSL requests
4856
if ($http_x_forwarded_proto != 'https') {
4957
return 301 https://$host$request_uri;
@@ -64,6 +72,11 @@ http {
6472

6573
port_in_redirect off;
6674

75+
gzip on;
76+
gzip_proxied any;
77+
gzip_comp_level 4;
78+
gzip_types text/css application/javascript image/svg+xml;
79+
6780
# Redirect all non-SSL requests
6881
if ($http_x_forwarded_proto != 'https') {
6982
return 301 https://$host$request_uri;
@@ -101,6 +114,12 @@ http {
101114

102115
root /app/.www;
103116

117+
location /assets {
118+
proxy_cache STATIC;
119+
proxy_ignore_headers Cache-Control;
120+
proxy_cache_valid 60m;
121+
}
122+
104123
location / {
105124
index index.html index.htm;
106125
}

heroku-start.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1+
# Initialize cache directory.
2+
mkdir -p cache/nginx
3+
echo 'script=heroku-start at=cache-initialized'
4+
#
15
bin/start-nginx-solo

0 commit comments

Comments
 (0)