nginx.conf 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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 scs1739178580156_api.ygtxfj.com_server.crt; # 证书文件(含完整链)
  30. ssl_certificate_key scs1739178580156_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. #error_page 404 /404.html;
  93. # redirect server error pages to the static page /50x.html
  94. #
  95. error_page 500 502 503 504 /50x.html;
  96. location = /50x.html {
  97. root html;
  98. }
  99. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  100. #
  101. #location ~ \.php$ {
  102. # proxy_pass http://127.0.0.1;
  103. #}
  104. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  105. #
  106. #location ~ \.php$ {
  107. # root html;
  108. # fastcgi_pass 127.0.0.1:9000;
  109. # fastcgi_index index.php;
  110. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  111. # include fastcgi_params;
  112. #}
  113. # deny access to .htaccess files, if Apache's document root
  114. # concurs with nginx's one
  115. #
  116. #location ~ /\.ht {
  117. # deny all;
  118. #}
  119. }
  120. # another virtual host using mix of IP-, name-, and port-based configuration
  121. #
  122. #server {
  123. # listen 8000;
  124. # listen somename:8080;
  125. # server_name somename alias another.alias;
  126. # location / {
  127. # root html;
  128. # index index.html index.htm;
  129. # }
  130. #}
  131. # HTTPS server
  132. #
  133. #server {
  134. # listen 443 ssl;
  135. # server_name localhost;
  136. # ssl_certificate cert.pem;
  137. # ssl_certificate_key cert.key;
  138. # ssl_session_cache shared:SSL:1m;
  139. # ssl_session_timeout 5m;
  140. # ssl_ciphers HIGH:!aNULL:!MD5;
  141. # ssl_prefer_server_ciphers on;
  142. # location / {
  143. # root html;
  144. # index index.html index.htm;
  145. # }
  146. #}
  147. }