nginx-production.conf 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # 若依前后端部署Nginx配置
  2. # 复制此内容到 C:\nginx\conf\nginx.conf 的 http 块中
  3. server {
  4. listen 80;
  5. server_name localhost;
  6. # 前端静态文件
  7. location / {
  8. root html; # 指向 C:\nginx\html(前端dist文件)
  9. index index.html index.htm;
  10. try_files $uri $uri/ /index.html;
  11. }
  12. # 后端API代理 - 关键配置
  13. location /prod-api/ {
  14. proxy_pass http://localhost:8080/prod-api/; # 代理到后端
  15. proxy_set_header Host $host;
  16. proxy_set_header X-Real-IP $remote_addr;
  17. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  18. proxy_set_header X-Forwarded-Proto $scheme;
  19. # 超时设置
  20. proxy_connect_timeout 60s;
  21. proxy_send_timeout 60s;
  22. proxy_read_timeout 60s;
  23. }
  24. # 上传文件访问
  25. location /uploads/ {
  26. proxy_pass http://localhost:8080/uploads/; # 代理到后端
  27. autoindex on;
  28. }
  29. # profile文件访问(自定义服务GeoJSON等)
  30. location /profile/ {
  31. proxy_pass http://localhost:8080/prod-api/; # 代理到后端(带context-path)
  32. proxy_set_header Host $host;
  33. proxy_set_header X-Real-IP $remote_addr;
  34. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  35. proxy_set_header X-Forwarded-Proto $scheme;
  36. }
  37. # 错误页面
  38. error_page 404 /index.html;
  39. error_page 500 502 503 504 /50x.html;
  40. location = /50x.html {
  41. root html;
  42. }
  43. }