This commit is contained in:
vipg
2025-11-12 17:10:40 +08:00
parent f5277b087b
commit 8fba06bca3
4 changed files with 119 additions and 2 deletions

View File

@@ -0,0 +1,37 @@
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.html; # 入口文件指向项目根目录的 index.html
# 支持 SPA 路由重写关键解决刷新404
location / {
try_files $uri $uri/ /index.html;
add_header Cache-Control "no-cache"; # 入口文件不缓存
}
# 静态资源缓存配置JS/CSS/图片等)
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|otf)$ {
expires 7d; # 缓存7天
add_header Cache-Control "public, max-age=604800";
add_header Access-Control-Allow-Origin "*"; # 允许跨域(可选)
}
# 禁止访问隐藏文件(如 .git、.env 等)
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
# 优化 Nginx 响应速度
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# 关闭不必要的日志
access_log off;
error_log /var/log/nginx/error.log warn;
}