nginx.conf 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. server {
  2. listen 80;
  3. server_name localhost;
  4. charset utf-8;
  5. # 静态资源根目录
  6. root /usr/share/nginx/html;
  7. index index.html;
  8. # gzip 压缩
  9. gzip on;
  10. gzip_min_length 1k;
  11. gzip_comp_level 6;
  12. gzip_types text/plain text/css application/json application/javascript
  13. text/xml application/xml application/xml+rss text/javascript
  14. image/svg+xml;
  15. gzip_vary on;
  16. gzip_disable "MSIE [1-6]\.";
  17. # 静态资源缓存(Vite 构建产物带 hash,可长期缓存)
  18. location /assets/ {
  19. expires 1y;
  20. add_header Cache-Control "public, immutable";
  21. }
  22. # 后端 API 代理(目前未接入,先预留)
  23. location /prod-api/ {
  24. proxy_pass http://backend:8080/;
  25. proxy_set_header Host $host;
  26. proxy_set_header X-Real-IP $remote_addr;
  27. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  28. proxy_set_header X-Forwarded-Proto $scheme;
  29. }
  30. # Vue Router history 模式 — 所有未匹配路径回退到 index.html
  31. location / {
  32. try_files $uri $uri/ /index.html;
  33. }
  34. # 禁止访问隐藏文件
  35. location ~ /\. {
  36. deny all;
  37. }
  38. }