Files
dukang_official/deploy/nginx-cache.conf
T
2026-08-26 00:44:25 +08:00

38 lines
1.2 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Nginx / 宝塔:分层缓存片段(并入 server {} 后 reload)
# Vite 构建产物在 /assets/ 下且文件名含 content hash → 长缓存
# 注意:若 public 静态图也挂在 /assets/,与构建产物同前缀时用扩展名区分
location = /index.html {
add_header Cache-Control "public, max-age=0, must-revalidate";
}
location ~* \.html$ {
add_header Cache-Control "public, max-age=0, must-revalidate";
}
# Vite 打出的带 hash 的 JS/CSS(部署后路径通常为 /assets/index-xxxxx.js)
location ~* ^/assets/.*\.(?:js|css)$ {
add_header Cache-Control "public, max-age=31536000, immutable";
try_files $uri =404;
}
# 同域兜底图片(生产主图应走 OSS;若仍有本地图则 7 天)
location ~* ^/assets/.*\.(?:png|jpe?g|gif|webp|svg|ico)$ {
add_header Cache-Control "public, max-age=604800";
try_files $uri =404;
}
location = /robots.txt {
add_header Cache-Control "public, max-age=0, must-revalidate";
}
location = /sitemap.xml {
add_header Cache-Control "public, max-age=0, must-revalidate";
default_type application/xml;
}
# SPA 路由回退(按实际根目录调整)
# location / {
# try_files $uri $uri/ /index.html;
# }