mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 08:11:54 +00:00
update ttl, use file based hashing to prevent stale data.
This commit is contained in:
+93
-10
@@ -40,24 +40,107 @@ server {
|
||||
access_log /var/log/nginx/access.log;
|
||||
error_log /var/log/nginx/error.log;
|
||||
|
||||
# Static file caching for the "static" directory
|
||||
location ~ ^/static/(.*)$ {
|
||||
# Static file handling with proper MIME types and consistent caching
|
||||
location ~* ^/static/(.*)$ {
|
||||
proxy_pass http://127.0.0.1:3000;
|
||||
|
||||
# Include MIME types
|
||||
include /etc/nginx/mime.types;
|
||||
|
||||
# Cache configuration for static files
|
||||
proxy_cache STATIC;
|
||||
proxy_ignore_headers Cache-Control;
|
||||
proxy_cache_valid 200 302 60m;
|
||||
proxy_cache_valid 200 302 24h; # Cache successful responses for 24 hours
|
||||
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
|
||||
proxy_cache_lock on;
|
||||
|
||||
# Show cache status in response headers
|
||||
add_header X-Cache-Status $upstream_cache_status;
|
||||
|
||||
# Standard proxy headers
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
|
||||
# Default cache policy for static files
|
||||
add_header Cache-Control "public, max-age=86400"; # 24 hours
|
||||
}
|
||||
|
||||
# Binary files caching
|
||||
location ~* \.(bin|dat|exe|dll|so|dylib)$ {
|
||||
proxy_pass http://127.0.0.1:3000;
|
||||
add_header Cache-Control "public, max-age=31536000, immutable"; # 1 year for binary files
|
||||
|
||||
proxy_cache STATIC;
|
||||
proxy_cache_valid 200 302 24h;
|
||||
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
|
||||
proxy_cache_lock on;
|
||||
add_header X-Cache-Status $upstream_cache_status;
|
||||
|
||||
# Cache bypass if needed (for development/debugging)
|
||||
proxy_cache_bypass $http_pragma $http_authorization;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
# Specific file type caching rules (outside the /static/ location)
|
||||
location ~* \.js$ {
|
||||
proxy_pass http://127.0.0.1:3000;
|
||||
add_header Content-Type application/javascript;
|
||||
add_header Cache-Control "public, max-age=31536000, immutable"; # 1 year for JS files
|
||||
|
||||
# No TTL as requested (browser will check each time)
|
||||
expires -1;
|
||||
add_header Cache-Control "no-cache";
|
||||
proxy_cache STATIC;
|
||||
proxy_cache_valid 200 302 24h;
|
||||
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
|
||||
proxy_cache_lock on;
|
||||
add_header X-Cache-Status $upstream_cache_status;
|
||||
|
||||
# Standard proxy headers
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
location ~* \.css$ {
|
||||
proxy_pass http://127.0.0.1:3000;
|
||||
add_header Content-Type text/css;
|
||||
add_header Cache-Control "public, max-age=31536000, immutable"; # 1 year for CSS files
|
||||
|
||||
proxy_cache STATIC;
|
||||
proxy_cache_valid 200 302 24h;
|
||||
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
|
||||
proxy_cache_lock on;
|
||||
add_header X-Cache-Status $upstream_cache_status;
|
||||
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
location ~* \.html$ {
|
||||
proxy_pass http://127.0.0.1:3000;
|
||||
add_header Content-Type text/html;
|
||||
add_header Cache-Control "public, max-age=86400"; # 24 hours for HTML files
|
||||
|
||||
proxy_cache STATIC;
|
||||
proxy_cache_valid 200 302 24h;
|
||||
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
|
||||
proxy_cache_lock on;
|
||||
add_header X-Cache-Status $upstream_cache_status;
|
||||
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
# Root location - make sure index.html is the default
|
||||
location = / {
|
||||
proxy_pass http://127.0.0.1:3000;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection $connection_upgrade;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
|
||||
Reference in New Issue
Block a user