nginx.conf 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. location / {
  26. root /usr/share/nginx/html/frontend/dist;
  27. index index.html index.htm;
  28. try_files $uri $uri/ /index.html; #解决页面刷新404问题
  29. }
  30. # 前端代理 - /web访问前端(http://192.168.0.247/web)
  31. #location / {
  32. # alias /usr/share/nginx/html/frontend/dist;
  33. # try_files $uri $uri/ /index.html; #解决页面刷新404问题
  34. #}
  35. # 小程序代理 - /app访问小程序(http://192.168.0.247/app)
  36. #location /app {
  37. # alias /usr/share/nginx/html/fastapp/dist/build/h5;
  38. # try_files $uri $uri/ /app/index.html; #解决页面刷新404问题
  39. #}
  40. # 后端代理 - /api/v1转发到内网后端服务
  41. location /api/v1 {
  42. proxy_set_header Host $host;
  43. proxy_set_header X-Real-IP $remote_addr;
  44. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  45. proxy_set_header X-Forwarded-Proto $scheme;
  46. proxy_set_header X-NginX-Proxy true;
  47. proxy_connect_timeout 300s;
  48. proxy_send_timeout 300s;
  49. proxy_read_timeout 300s;
  50. # 替换为你的后端服务地址(内网IP+端口,若后端在docker内可填容器名/内网IP)
  51. proxy_pass http://192.168.0.247:8001;
  52. # WebSocket 支持(保留,不影响HTTP)
  53. proxy_http_version 1.1;
  54. proxy_set_header Upgrade $http_upgrade;
  55. proxy_set_header Connection "upgrade";
  56. }
  57. # 错误页面配置
  58. error_page 500 502 503 504 /50x.html;
  59. location = /50x.html {
  60. root /usr/share/nginx/html;
  61. }
  62. }
  63. }