nginx.conf 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # nginx.conf
  2. worker_processes 5;
  3. events {
  4. worker_connections 1024;
  5. }
  6. http {
  7. include mime.types;
  8. default_type application/octet-stream;
  9. client_max_body_size 200m;
  10. sendfile on;
  11. keepalive_timeout 65;
  12. server {
  13. listen 80; # 容器内端口
  14. server_name localhost;
  15. # 前端静态资源目录(对应容器内的 /usr/share/nginx/html)
  16. root /usr/share/nginx/html;
  17. index index.html;
  18. # 关键:处理 VUE Router history 模式(避免刷新 404)
  19. location / {
  20. try_files $uri $uri/ /index.html; # 所有路由指向 index.html
  21. }
  22. # 关键:反向代理 API(解决跨域,替换为你的真实后端地址)
  23. location /prod-api/ {
  24. proxy_pass http://192.168.58.159:7772/; # 后端 API 地址(末尾加 / 避免路径拼接问题)
  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; # 传递 HTTPS 协议
  29. }
  30. }
  31. }