nginx.default.conf 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. server {
  2. listen 8080;
  3. server_name localhost;
  4. root /usr/share/nginx/html;
  5. index index.html index.htm;
  6. # 安全头
  7. add_header X-Frame-Options "SAMEORIGIN" always;
  8. add_header X-XSS-Protection "1; mode=block" always;
  9. add_header X-Content-Type-Options "nosniff" always;
  10. add_header Referrer-Policy "no-referrer-when-downgrade" always;
  11. # Gzip 压缩
  12. gzip on;
  13. gzip_vary on;
  14. gzip_min_length 1024;
  15. gzip_comp_level 6;
  16. gzip_types
  17. text/plain
  18. text/css
  19. text/xml
  20. text/javascript
  21. application/javascript
  22. application/json
  23. application/xml+rss
  24. application/atom+xml
  25. image/svg+xml;
  26. # 主路由 - SPA 支持
  27. location / {
  28. try_files $uri $uri/ /index.html;
  29. # 安全头
  30. add_header Cache-Control "no-cache, no-store, must-revalidate";
  31. add_header Pragma "no-cache";
  32. add_header Expires "0";
  33. }
  34. # 静态资源缓存
  35. location /static/ {
  36. expires 1y;
  37. add_header Cache-Control "public, immutable";
  38. access_log off;
  39. }
  40. # 字体文件
  41. location ~* \.(woff|woff2|ttf|eot)$ {
  42. expires 1y;
  43. add_header Cache-Control "public, immutable";
  44. access_log off;
  45. }
  46. # 图片文件
  47. location ~* \.(png|jpg|jpeg|gif|ico|svg)$ {
  48. expires 1y;
  49. add_header Cache-Control "public, immutable";
  50. access_log off;
  51. }
  52. # CSS 和 JS 文件
  53. location ~* \.(css|js)$ {
  54. expires 1y;
  55. add_header Cache-Control "public, immutable";
  56. access_log off;
  57. }
  58. # manifest 和 service worker
  59. location ~* \.(manifest\.json|sw\.js)$ {
  60. expires 0;
  61. add_header Cache-Control "no-cache, no-store, must-revalidate";
  62. access_log off;
  63. }
  64. # 禁止访问隐藏文件
  65. location ~ /\. {
  66. deny all;
  67. access_log off;
  68. log_not_found off;
  69. }
  70. # 错误页面
  71. error_page 404 /index.html;
  72. error_page 500 502 503 504 /50x.html;
  73. location = /50x.html {
  74. root /usr/share/nginx/html;
  75. }
  76. }