server { listen 80; server_name localhost; root /usr/share/nginx/html; index index.html; # 支持 history 路由模式 location / { try_files $uri $uri/ /index.html; } # 缓存静态资源 location /assets { expires 1y; add_header Cache-Control "public, no-transform"; } # 禁止访问 . 文件 location ~ /\. { deny all; } }