# Nginx 反向代理(手写配置) > 若使用 **宝塔面板**,请直接看 **[BAOTA.md](./BAOTA.md)**,内含完整 `#PROXY-START/` 配置与操作步骤。 浏览器访问 `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 未正确反代。 ## 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. AI 接口测试 ```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 页面。