Browse Source

feat: Set Cache-Control headers in nginx configs

Owen Diffey 1 year ago
parent
commit
10d5728ddd
2 changed files with 19 additions and 1 deletions
  1. 6 0
      frontend/dev.nginx.conf
  2. 13 1
      frontend/prod.nginx.conf

+ 6 - 0
frontend/dev.nginx.conf

@@ -20,6 +20,9 @@ http {
         server_name localhost;
 
         location / {
+            expires off;
+            add_header Cache-Control "public, max-age=0, s-maxage=0, must-revalidate" always;
+
             proxy_set_header X-Real-IP $remote_addr;
 			proxy_set_header X-Forwarded-For $remote_addr;
 			proxy_set_header Host $host;
@@ -33,6 +36,9 @@ http {
         }
 
         location /backend {
+            expires off;
+            add_header Cache-Control "public, max-age=0, s-maxage=0, must-revalidate" always;
+
             proxy_set_header X-Real-IP  $remote_addr;
 			proxy_set_header X-Forwarded-For $remote_addr;
 			proxy_set_header Host $host;

+ 13 - 1
frontend/prod.nginx.conf

@@ -21,6 +21,12 @@ http {
 
         root /opt/app/build;
 
+        # all assets are either static or contain hash in filename, cache forever
+        location ^~ /assets/ {
+            add_header Cache-Control "public, max-age=31536000, s-maxage=31536000, immutable";
+            try_files $uri =404;
+        }
+
         # all workbox scripts are compiled with hash in filename, cache forever
         location ^~ /workbox- {
             add_header Cache-Control "public, max-age=31536000, s-maxage=31536000, immutable";
@@ -28,10 +34,16 @@ http {
         }
 
         location / {
-            try_files $uri /$uri /index.html =404;
+            autoindex off;
+            expires off;
+            add_header Cache-Control "public, max-age=0, s-maxage=0, must-revalidate" always;
+            try_files $uri /index.html =404;
         }
 
         location /backend {
+            expires off;
+            add_header Cache-Control "public, max-age=0, s-maxage=0, must-revalidate" always;
+
             proxy_set_header X-Real-IP $remote_addr;
             proxy_set_header X-Forwarded-For $remote_addr;
             proxy_set_header Host $host;