Files
sundynix-agentix/sundynix-admin/nginx.conf
T
Blizzard 08c4d94187 fix(deploy): nginx 反代补 WebSocket 升级头(语音/本地执行器)
nginx 默认吃掉 Upgrade/Connection 头,被代理的 WS 永远握不上手——现象是
HTTP 接口全正常、只有 WebSocket 报 ws error(直连网关端口则一切正常)。
/api/v1/voice/stream(语音会话)与 /api/v1/local/runner(本地执行器)都走 WS。

用 map 而非写死 "upgrade":普通请求带 Connection: upgrade 会干扰 keepalive。

注:生产 compose 无 admin 服务(admin 已 go:embed 进 gateway),线上域名前面
那层 nginx 是服务器手工配的,需同样补这两行。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-25 14:40:21 +08:00

44 lines
1.7 KiB
Nginx Configuration File

# 运维控制台静态托管 + 反代网关 API(一个 URL 同时给前端与 /api)。
# WebSocket 升级:nginx 默认会吃掉 Upgrade/Connection 头,被代理的 WS 永远握手不成功
# (现象:HTTP 接口全好,只有 WS 报 ws error)。语音会话 /api/v1/voice/stream 与
# 本地执行器 /api/v1/local/runner 都走 WS,必须显式转发。
# 用 map 而非写死 "upgrade":普通请求带上 Connection: upgrade 会干扰 keepalive。
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.html;
# SPA 路由:找不到文件回退 index.html(前端路由接管)。
location / {
try_files $uri $uri/ /index.html;
}
# 网关 API:反代到 compose 网络内的 gateway 服务。
location /api/ {
proxy_pass http://gateway:8080;
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;
# WebSocket(语音会话 / 本地执行器):不转发这两个头则握手必失败。
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
# SSE(token 流 / 执行轨迹):关闭缓冲 + 长超时,否则流式会被攒住/断开。
proxy_buffering off;
proxy_cache off;
proxy_read_timeout 1h;
proxy_send_timeout 1h;
}
# 健康/指标直通(运维探活)。
location = /healthz { proxy_pass http://gateway:8080; }
location = /readyz { proxy_pass http://gateway:8080; }
}