# 前端容器内部 nginx 配置 # 遵循瑞小美系统技术栈标准 - 性能优化版 server { listen 80; server_name localhost; root /usr/share/nginx/html; index index.html; # 启用 gzip 压缩 gzip on; gzip_vary on; gzip_min_length 1024; gzip_proxied any; gzip_comp_level 6; gzip_buffers 16 8k; gzip_types text/plain text/css text/xml application/json application/javascript application/xml+rss application/atom+xml image/svg+xml; # 启用预压缩文件(.gz) gzip_static on; # 静态资源缓存 - 带哈希的文件长期缓存 location /assets { expires 1y; add_header Cache-Control "public, max-age=31536000, immutable"; # 安全头 add_header X-Content-Type-Options nosniff; } # JS/CSS 文件缓存 location ~* \.(js|css)$ { expires 1y; add_header Cache-Control "public, max-age=31536000, immutable"; } # 图片资源缓存 location ~* \.(ico|gif|jpg|jpeg|png|webp|svg)$ { expires 30d; add_header Cache-Control "public, max-age=2592000"; } # 字体文件缓存 location ~* \.(woff|woff2|ttf|eot)$ { expires 1y; add_header Cache-Control "public, max-age=31536000"; add_header Access-Control-Allow-Origin "*"; } # HTML 文件不缓存(SPA 入口) location = /index.html { expires -1; add_header Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate"; } # SPA 路由支持 location / { try_files $uri $uri/ /index.html; # 安全头 add_header X-Frame-Options "SAMEORIGIN" always; add_header X-XSS-Protection "1; mode=block" always; add_header X-Content-Type-Options "nosniff" always; } # 健康检查 location /health { access_log off; return 200 "healthy\n"; add_header Content-Type text/plain; } # 禁止访问隐藏文件 location ~ /\. { deny all; access_log off; log_not_found off; } }