Fix AI result panel visibility and nginx streaming headers.

ResultAI had h-0 collapsing output; add X-Accel-Buffering no, clearer fetch errors, and NGINX.md for gate proxy setup.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-10 22:56:22 +08:00
parent 38bbc7145a
commit 39181f21ad
7 changed files with 118 additions and 39 deletions
+60
View File
@@ -0,0 +1,60 @@
# Nginx 反代 + AI 流式输出
浏览器访问 `https://你的域名/api/ai` 必须能到达 Next.js(3130),且**关闭缓冲**,否则页面上 AI 解读会一直空白或等到超时。
## 1. 验证
在**服务器**上分别测试:
```bash
# 本地直连(应成功)
curl -s http://127.0.0.1:3130/api/health
# 经域名(也必须成功,否则是 Nginx 问题)
curl -s https://gate.hyf2.cc/api/health
```
若本地成功、域名 404 或返回 HTML,说明 Nginx 未正确反代 `/api/`
## 2. 推荐配置
```nginx
server {
listen 443 ssl http2;
server_name gate.hyf2.cc;
# ssl_certificate ...;
location / {
proxy_pass http://127.0.0.1:3130;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# AI 流式:必须关闭缓冲
proxy_buffering off;
proxy_cache off;
proxy_read_timeout 300s;
proxy_send_timeout 300s;
chunked_transfer_encoding on;
}
}
```
修改后:
```bash
nginx -t && systemctl reload nginx
```
## 3. 浏览器测试
```bash
curl -N -X POST https://gate.hyf2.cc/api/ai \
-H "Content-Type: application/json" \
-d '{"mode":"bazi","payload":{"input":{"date":"1990-01-01","time":"12:00","gender":"male","longitude":120},"question":"测试","birthPlaceName":"上海市"}}'
```
应看到中文流式输出,而不是 HTML 404 页面。