nginx.conf 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. # 防点击劫持 / 基础安全响应头
  19. add_header X-Frame-Options "SAMEORIGIN" always;
  20. add_header Content-Security-Policy "frame-ancestors 'self';" always;
  21. add_header X-Content-Type-Options "nosniff" always;
  22. # 关键:处理 VUE Router history 模式(避免刷新 404)
  23. location / {
  24. try_files $uri $uri/ /index.html; # 所有路由指向 index.html
  25. }
  26. # 关键:反向代理 API(解决跨域,替换为你的真实后端地址)
  27. location /prod-api/ {
  28. proxy_pass http://192.168.52.215:7773/; # 后端 API 地址(末尾加 / 避免路径拼接问题)
  29. proxy_set_header Host $host;
  30. proxy_set_header X-Real-IP $remote_addr;
  31. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  32. proxy_set_header X-Forwarded-Proto $scheme; # 传递 HTTPS 协议
  33. }
  34. }
  35. }