add caching rules, tell client caching for 1 year, but no caching for index.html

This commit is contained in:
einhornimmond 2025-05-21 15:27:51 +02:00
parent a40ae18f2b
commit 686d1749e9
2 changed files with 32 additions and 0 deletions

View File

@ -51,6 +51,12 @@ server {
rewrite ^/vue/?(.*)$ /$1 permanent;
}
# caching rules for assets
location ~* \.(?:js|css|woff2?|ttf|otf|eot|jpg|jpeg|png|gif|svg|webp|ico)$ {
add_header Cache-Control "public, max-age=31536000, immutable";
try_files $uri =404;
}
# Frontend (default)
location / {
@ -59,6 +65,11 @@ server {
root $PROJECT_ROOT/frontend/build/;
index index.html;
try_files $uri $uri/ /index.html = 404;
# don't cache index.html
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma "no-cache";
add_header Expires 0;
access_log $GRADIDO_LOG_PATH/nginx-access.frontend.log gradido_log;
error_log $GRADIDO_LOG_PATH/nginx-error.frontend.log warn;
@ -119,6 +130,11 @@ server {
index index.html;
try_files $uri $uri/ /index.html = 404;
# don't cache index.html
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma "no-cache";
add_header Expires 0;
access_log $GRADIDO_LOG_PATH/nginx-access.admin.log gradido_log;
error_log $GRADIDO_LOG_PATH/nginx-error.admin.log warn;
}

View File

@ -36,6 +36,12 @@ server {
rewrite ^/vue/?(.*)$ /$1 permanent;
}
# caching rules for assets
location ~* \.(?:js|css|woff2?|ttf|otf|eot|jpg|jpeg|png|gif|svg|webp|ico)$ {
add_header Cache-Control "public, max-age=31536000, immutable";
try_files $uri =404;
}
# Frontend (default)
location / {
#limit_req zone=frontend burst=40 nodelay;
@ -44,6 +50,11 @@ server {
index index.html;
try_files $uri $uri/ /index.html = 404;
# don't cache index.html
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma "no-cache";
add_header Expires 0;
access_log $GRADIDO_LOG_PATH/nginx-access.frontend.log gradido_log;
error_log $GRADIDO_LOG_PATH/nginx-error.frontend.log warn;
}
@ -103,6 +114,11 @@ server {
index index.html;
try_files $uri $uri/ /index.html = 404;
# don't cache index.html
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma "no-cache";
add_header Expires 0;
access_log $GRADIDO_LOG_PATH/nginx-access.admin.log gradido_log;
error_log $GRADIDO_LOG_PATH/nginx-error.admin.log warn;
}