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>
This commit is contained in:
@@ -1,4 +1,14 @@
|
||||
# 运维控制台静态托管 + 反代网关 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 _;
|
||||
@@ -17,6 +27,9 @@ server {
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user