server { listen 80; server_name localhost; # gzip 压缩 gzip on; gzip_vary on; gzip_proxied any; gzip_comp_level 6; gzip_types text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml; # 静态资源目录 root /usr/share/nginx/html; index index.html; # 健康检查端点 location /health { access_log off; return 200 'ok'; add_header Content-Type text/plain; } # 静态资源缓存(JS/CSS/图片) location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ { expires 1y; add_header Cache-Control "public, immutable"; access_log off; } # Vue Router history 模式支持 location / { try_files $uri $uri/ /index.html; } # 禁止访问隐藏文件 location ~ /\. { deny all; access_log off; log_not_found off; } }