42 lines
1.5 KiB
Nginx Configuration File
42 lines
1.5 KiB
Nginx Configuration File
server_tokens off;
|
|
charset utf-8;
|
|
|
|
server {
|
|
listen 80;
|
|
server_name _;
|
|
root /usr/share/nginx/html;
|
|
index index.html;
|
|
|
|
# Security headers
|
|
add_header X-Frame-Options "SAMEORIGIN" always;
|
|
add_header X-Content-Type-Options "nosniff" always;
|
|
add_header X-XSS-Protection "1; mode=block" always;
|
|
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
|
add_header Permissions-Policy "camera=(), microphone=(), geolocation=()" always;
|
|
|
|
# 设计稿迭代期:CSS/JS 不带 hash,不能用 immutable,否则改了浏览器仍吃旧版
|
|
# 缓存 1 小时 + must-revalidate(过期后用 If-Modified-Since 回源验证,服务器没改返回 304,改了取新文件)
|
|
location ~* \.(css|js)$ {
|
|
expires 1h;
|
|
add_header Cache-Control "public, must-revalidate";
|
|
}
|
|
|
|
# 图片/字体/媒体:可以缓存稍长(改动频率低),仍允许重新验证
|
|
location ~* \.(png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot|mp4|webm)$ {
|
|
expires 7d;
|
|
add_header Cache-Control "public, must-revalidate";
|
|
}
|
|
|
|
# HTML:不进浏览器磁盘缓存,每次都问服务器有没有新版本
|
|
location ~* \.html$ {
|
|
add_header Cache-Control "no-cache, must-revalidate" always;
|
|
expires off;
|
|
}
|
|
|
|
# Multi-page (not SPA): try exact file, then .html fallback (friendly URLs), then 404.
|
|
# NEVER fallback to index.html — that masks 404s for a multi-entry design shelf.
|
|
location / {
|
|
try_files $uri $uri/ $uri.html =404;
|
|
}
|
|
}
|