nginx.conf 869 B

123456789101112131415161718192021222324252627282930
  1. server {
  2. listen 80;
  3. server_name localhost; # 替换为您的域名
  4. root /usr/share/nginx/html; # 替换为您的项目构建后的文件路径
  5. index index.html;
  6. location / {
  7. try_files $uri $uri/ /index.html; # 将所有请求重定向到index.html
  8. add_header Cache-Control "no-cache, no-store, must-revalidate";
  9. add_header Pragma "no-cache";
  10. add_header Expires "0";
  11. }
  12. # 静态资源缓存设置
  13. location /assets {
  14. expires 1y;
  15. add_header Cache-Control "public";
  16. access_log off;
  17. }
  18. # 处理API请求
  19. location /api {
  20. proxy_pass http://your-backend-server; # 替换为您的后端服务地址
  21. proxy_set_header Host $host;
  22. proxy_set_header X-Real-IP $remote_addr;
  23. }
  24. error_page 404 /index.html; # 将404错误重定向到首页
  25. }