nginx.conf 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # For more information on configuration, see:
  2. # * Official English Documentation: http://nginx.org/en/docs/
  3. # * Official Russian Documentation: http://nginx.org/ru/docs/
  4. ########### 每个指令必须有分号结束。#################
  5. worker_processes 1; # 允许生成的进程数,默认为1
  6. pid /var/run/nginx.pid; # 指定 Nginx 进程运行文件存放地址
  7. error_log /var/log/nginx/error.log;
  8. events {
  9. accept_mutex on; # 设置网络连接序列化,防止惊群现象发生,默认为on
  10. multi_accept on; # 设置一个进程是否同时接受多个网络连接,默认为off
  11. use epoll; # 事件驱动模型,select|poll|kqueue|epoll|resig|/dev/poll|eventport
  12. worker_connections 1024; # 最大连接数,默认为512
  13. }
  14. http {
  15. include mime.types; # 文件扩展名与文件类型映射表
  16. default_type application/octet-stream; # 默认文件类型,默认为text/plain
  17. # 访问服务日志
  18. access_log on;
  19. sendfile on; # 允许sendfile方式传输文件,默认为off
  20. keepalive_timeout 75; # 连接超时时间,默认为75秒
  21. # 仅保留HTTP server块(删除HTTPS和域名重定向)
  22. server {
  23. listen 80; # 内网仅用80端口访问
  24. server_name _; # 匹配所有IP/无域名场景,替代原域名
  25. # 官网代理 - 根路径访问官网(IP+端口直接访问)
  26. location / {
  27. root /usr/share/nginx/html/fastdocs/dist;
  28. index index.html index.htm;
  29. try_files $uri $uri/ /index.html; #解决页面刷新404问题
  30. }
  31. # 前端代理 - /web访问前端(http://192.168.0.247/web)
  32. location /web {
  33. alias /usr/share/nginx/html/frontend/dist;
  34. try_files $uri $uri/ /web/index.html; #解决页面刷新404问题
  35. }
  36. # 小程序代理 - /app访问小程序(http://192.168.0.247/app)
  37. location /app {
  38. alias /usr/share/nginx/html/fastapp/dist/build/h5;
  39. try_files $uri $uri/ /app/index.html; #解决页面刷新404问题
  40. }
  41. # 后端代理 - /api/v1转发到内网后端服务
  42. location /api/v1 {
  43. proxy_set_header Host $host;
  44. proxy_set_header X-Real-IP $remote_addr;
  45. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  46. proxy_set_header X-Forwarded-Proto $scheme;
  47. proxy_set_header X-NginX-Proxy true;
  48. proxy_connect_timeout 300s;
  49. proxy_send_timeout 300s;
  50. proxy_read_timeout 300s;
  51. # 替换为你的后端服务地址(内网IP+端口,若后端在docker内可填容器名/内网IP)
  52. proxy_pass http://192.168.0.247:8001;
  53. # WebSocket 支持(保留,不影响HTTP)
  54. proxy_http_version 1.1;
  55. proxy_set_header Upgrade $http_upgrade;
  56. proxy_set_header Connection "upgrade";
  57. }
  58. # 错误页面配置
  59. error_page 500 502 503 504 /50x.html;
  60. location = /50x.html {
  61. root /usr/share/nginx/html;
  62. }
  63. }
  64. }