nginx.conf 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #user nobody;
  2. worker_processes 1;
  3. error_log logs/error.log debug;
  4. #error_log logs/error.log notice;
  5. #error_log logs/error.log info;
  6. #pid logs/nginx.pid;
  7. events {
  8. worker_connections 1024;
  9. }
  10. http {
  11. include mime.types;
  12. default_type application/octet-stream;
  13. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  14. # '$status $body_bytes_sent "$http_referer" '
  15. # '"$http_user_agent" "$http_x_forwarded_for"';
  16. #access_log logs/access.log main;
  17. sendfile on;
  18. #tcp_nopush on;
  19. #keepalive_timeout 0;
  20. keepalive_timeout 65;
  21. # 全局优化
  22. client_max_body_size 100M; # 允许大文件上传
  23. # 压缩传输
  24. gzip on;
  25. server {
  26. listen 3443;
  27. server_name localhost;
  28. #charset koi8-r;
  29. #access_log logs/host.access.log main;
  30. # 指向构建后的静态文件目录(使用相对路径)
  31. root ../build;
  32. index index.html;
  33. location / {
  34. try_files $uri $uri/ /index.html;
  35. }
  36. # 代理后端API请求(关键配置)
  37. location /api/ {
  38. proxy_pass http://localhost:8080/api/; # 后端服务地址
  39. # 连接后端超时(默认60秒)
  40. proxy_connect_timeout 60s;
  41. # 发送请求到后端的超时(默认60秒)
  42. proxy_send_timeout 600s;
  43. # 从后端读取响应的超时(默认60秒)
  44. proxy_read_timeout 600s;
  45. proxy_set_header Host $host;
  46. proxy_set_header X-Real-IP $remote_addr;
  47. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  48. }
  49. # 处理/ws路径的Socket.IO连接(需添加协议升级头)
  50. location /ws/ {
  51. proxy_pass http://localhost:8080;
  52. proxy_http_version 1.1;
  53. proxy_set_header Upgrade $http_upgrade;
  54. proxy_set_header Connection "Upgrade";
  55. proxy_set_header Host $host;
  56. proxy_set_header X-Real-IP $remote_addr;
  57. proxy_read_timeout 86400; # 保持长连接
  58. }
  59. # 其他路由代理(根据FastAPI挂载路径)
  60. location ~ ^/(ollama|openai|auth|users|chats|models|files|retrieval)/ {
  61. proxy_pass http://localhost:8080;
  62. proxy_set_header Host $host;
  63. proxy_set_header X-Forwarded-Proto $scheme;
  64. }
  65. # 若静态文件通过FastAPI服务(如/static和/cache路径)
  66. location /static/ {
  67. proxy_pass http://localhost:8080/static/;
  68. expires 30d; # 缓存优化
  69. }
  70. location /cache/ {
  71. proxy_pass http://localhost:8080/cache/;
  72. expires 1h;
  73. }
  74. #error_page 404 /404.html;
  75. # redirect server error pages to the static page /50x.html
  76. #
  77. error_page 500 502 503 504 /50x.html;
  78. location = /50x.html {
  79. root html;
  80. }
  81. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  82. #
  83. #location ~ \.php$ {
  84. # proxy_pass http://127.0.0.1;
  85. #}
  86. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  87. #
  88. #location ~ \.php$ {
  89. # root html;
  90. # fastcgi_pass 127.0.0.1:9000;
  91. # fastcgi_index index.php;
  92. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  93. # include fastcgi_params;
  94. #}
  95. # deny access to .htaccess files, if Apache's document root
  96. # concurs with nginx's one
  97. #
  98. #location ~ /\.ht {
  99. # deny all;
  100. #}
  101. }
  102. # another virtual host using mix of IP-, name-, and port-based configuration
  103. #
  104. #server {
  105. # listen 8000;
  106. # listen somename:8080;
  107. # server_name somename alias another.alias;
  108. # location / {
  109. # root html;
  110. # index index.html index.htm;
  111. # }
  112. #}
  113. # HTTPS server
  114. #
  115. #server {
  116. # listen 443 ssl;
  117. # server_name localhost;
  118. # ssl_certificate cert.pem;
  119. # ssl_certificate_key cert.key;
  120. # ssl_session_cache shared:SSL:1m;
  121. # ssl_session_timeout 5m;
  122. # ssl_ciphers HIGH:!aNULL:!MD5;
  123. # ssl_prefer_server_ciphers on;
  124. # location / {
  125. # root html;
  126. # index index.html index.htm;
  127. # }
  128. #}
  129. }