nginx.conf 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 ssl;
  27. server_name api.ygtxfj.com;
  28. # 证书路径
  29. ssl_certificate scs1746840414500_api.ygtxfj.com_server.crt; # 证书文件(含完整链)
  30. ssl_certificate_key scs1746840414500_api.ygtxfj.com_server.key; # 私钥文件
  31. #charset koi8-r;
  32. #access_log logs/host.access.log main;
  33. # 指向构建后的静态文件目录(使用相对路径)
  34. location / {
  35. proxy_pass http://localhost:8080;
  36. proxy_set_header Host $host;
  37. proxy_set_header X-Real-IP $remote_addr;
  38. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  39. proxy_set_header X-Forwarded-Proto $scheme;
  40. }
  41. # 从 /auth 页面提取参数到变量
  42. location /auth {
  43. add_header Set-Cookie "auth_token=$arg_token; Path=/api/; HttpOnly";
  44. # 存储参数到变量(需确保前端页面和 API 在同一个请求会话中)
  45. set $auth_token $arg_token;
  46. proxy_pass http://localhost:8080/auth;
  47. }
  48. # 代理后端API请求(关键配置)
  49. location /api/ {
  50. proxy_pass http://localhost:8080/api/; # 后端服务地址
  51. # 连接后端超时(默认60秒)
  52. proxy_connect_timeout 60s;
  53. # 发送请求到后端的超时(默认60秒)
  54. proxy_send_timeout 600s;
  55. # 从后端读取响应的超时(默认60秒)
  56. proxy_read_timeout 600s;
  57. proxy_set_header Host $host;
  58. proxy_set_header X-Real-IP $remote_addr;
  59. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  60. # 将 Cookie 值作为请求头或查询参数传递
  61. proxy_set_header X-Trusted-Token $cookie_auth_token;
  62. }
  63. # 处理/ws路径的Socket.IO连接(需添加协议升级头)
  64. location /ws/ {
  65. proxy_pass http://localhost:8080;
  66. proxy_http_version 1.1;
  67. proxy_set_header Upgrade $http_upgrade;
  68. proxy_set_header Connection "Upgrade";
  69. proxy_set_header Host $host;
  70. proxy_set_header X-Real-IP $remote_addr;
  71. proxy_read_timeout 86400; # 保持长连接
  72. }
  73. # 其他路由代理(根据FastAPI挂载路径)
  74. location ~ ^/(ollama|openai|users|chats|models|files|retrieval)/ {
  75. proxy_pass http://localhost:8080;
  76. proxy_set_header Host $host;
  77. proxy_set_header X-Forwarded-Proto $scheme;
  78. }
  79. # 若静态文件通过FastAPI服务(如/static和/cache路径)
  80. location /static/ {
  81. proxy_pass http://localhost:8080/static/;
  82. expires 30d; # 缓存优化
  83. }
  84. location /cache/ {
  85. proxy_pass http://localhost:8080/cache/;
  86. expires 1h;
  87. }
  88. location /fLxiFxSceH.txt {
  89. proxy_pass http://localhost:8080/static/fLxiFxSceH.txt;
  90. expires 30d; # 缓存优化
  91. }
  92. location /VyeGYE6pzK.txt {
  93. proxy_pass http://localhost:8080/static/VyeGYE6pzK.txt;
  94. expires 30d; # 缓存优化
  95. }
  96. #error_page 404 /404.html;
  97. # redirect server error pages to the static page /50x.html
  98. #
  99. error_page 500 502 503 504 /50x.html;
  100. location = /50x.html {
  101. root html;
  102. }
  103. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  104. #
  105. #location ~ \.php$ {
  106. # proxy_pass http://127.0.0.1;
  107. #}
  108. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  109. #
  110. #location ~ \.php$ {
  111. # root html;
  112. # fastcgi_pass 127.0.0.1:9000;
  113. # fastcgi_index index.php;
  114. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  115. # include fastcgi_params;
  116. #}
  117. # deny access to .htaccess files, if Apache's document root
  118. # concurs with nginx's one
  119. #
  120. #location ~ /\.ht {
  121. # deny all;
  122. #}
  123. }
  124. # another virtual host using mix of IP-, name-, and port-based configuration
  125. #
  126. # server {
  127. # listen 8000;
  128. # listen somename:8080;
  129. # server_name somename alias another.alias;
  130. # location / {
  131. # root html;
  132. # index index.html index.htm;
  133. # }
  134. # }
  135. # HTTPS server
  136. #
  137. server {
  138. listen 8125 ssl http2;
  139. server_name api.ygtxfj.com;
  140. # 证书路径
  141. ssl_certificate scs1746840414500_api.ygtxfj.com_server.crt; # 证书文件(含完整链)
  142. ssl_certificate_key scs1746840414500_api.ygtxfj.com_server.key; # 私钥文件
  143. #charset koi8-r;
  144. #access_log logs/host.access.log main;
  145. # 指向构建后的静态文件目录(使用相对路径)
  146. location / {
  147. proxy_pass http://localhost:8123;
  148. proxy_set_header Host $host;
  149. proxy_http_version 1.1;
  150. proxy_set_header Upgrade $http_upgrade;
  151. proxy_set_header Connection "upgrade";
  152. }
  153. location /api/websocket {
  154. proxy_pass http://localhost:8123/api/websocket;
  155. proxy_set_header Host $host;
  156. proxy_http_version 1.1;
  157. proxy_set_header Upgrade $http_upgrade;
  158. proxy_set_header Connection "upgrade";
  159. }
  160. }
  161. }