server { listen 80; server_name localhost; root /usr/share/nginx/html; index index.html; # SPA 路由支持 - 所有路径都返回 index.html location / { try_files $uri $uri/ /index.html; } # 静态资源缓存 location /assets { expires 1y; add_header Cache-Control "public, immutable"; } # gzip 压缩 gzip on; gzip_types text/plain text/css application/json application/javascript text/xml application/xml; gzip_min_length 1000; }