iloom-flatten/nginx.conf
Chever John 31ea850769
fix: add content hash to JS bundles and fix caching strategy
JS files were output as main.js without content hash, combined with
nginx's 30-day immutable cache. Browsers would never fetch updated code.

- Add [contenthash:8] to webpack output filenames in production
- Set index.html to no-cache so browsers always check for new bundles
- Only apply immutable cache to hashed filenames (*.abcdef01.js)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-30 02:25:33 +08:00

52 lines
1.5 KiB
Nginx Configuration File

server {
listen 3015;
server_name _;
root /usr/share/nginx/html;
index index.html;
# gzip
gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml text/javascript image/svg+xml;
gzip_min_length 256;
# API 反向代理
location /api/ {
proxy_pass http://gateway:8080;
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;
}
# WebSocket 反向代理
location /ws/ {
proxy_pass http://gateway:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_read_timeout 86400;
}
# SPA fallback — index.html must not be cached
location / {
try_files $uri $uri/ /index.html;
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma "no-cache";
add_header Expires "0";
}
# Hashed static assets — long-term cache is safe
location ~* \.[0-9a-f]{8}\.(js|css)$ {
expires 30d;
add_header Cache-Control "public, immutable";
}
# Other static assets (images, fonts) — moderate cache
location ~* \.(png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
expires 7d;
add_header Cache-Control "public";
}
}