Browser connects oRPC over wss://…/trpc (partysocket). The gmw-proxy nginx
only forwarded /api and /ws to the backend, so /trpc upgrades fell through to
Next.js SSR and the socket never opened ("WebSocket is not open"). Add a
/trpc location (WS upgrade headers) mirroring /ws. Backend already serves
oRPC on /trpc (HTTP RPCHandler + WS ORPCWebSocketServer on :4001).
Verified: ws://127.0.0.1:4001/trpc upgrade OPEN; SSR + server-side fetch RPCLink
also use /trpc directly so only the browser path was broken.
109 lines
4.0 KiB
Plaintext
109 lines
4.0 KiB
Plaintext
events {}
|
|
|
|
http {
|
|
include @NGINX_MIME@;
|
|
|
|
access_log /var/lib/gmw-proxy/nginx-access.log;
|
|
error_log /var/lib/gmw-proxy/nginx-error.log;
|
|
|
|
map $http_upgrade $connection_upgrade {
|
|
default upgrade;
|
|
'' close;
|
|
}
|
|
|
|
# Next.js standalone SSR server (backend-fetching on every render).
|
|
# Not for hand-editing: @NEXT_PORT@ is substituted at build time.
|
|
upstream gmw_next {
|
|
server 127.0.0.1:@NEXT_PORT@;
|
|
keepalive 16;
|
|
}
|
|
|
|
upstream gmw_backend {
|
|
server 127.0.0.1:4001;
|
|
keepalive 16;
|
|
}
|
|
|
|
server {
|
|
listen 4009;
|
|
server_name _;
|
|
|
|
# Use relative redirects (Location: /dashboard/) instead of absolute
|
|
# URLs that leak the internal listen port (4009) through the reverse proxy.
|
|
absolute_redirect off;
|
|
|
|
gzip on;
|
|
gzip_types text/plain text/css application/json application/javascript application/wasm image/svg+xml;
|
|
gzip_min_length 256;
|
|
|
|
# ── Backend REST ───────────────────────────────────────────────
|
|
location ^~ /api {
|
|
proxy_pass http://gmw_backend$uri$is_args$args;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Connection ""; # keepalive to backend
|
|
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;
|
|
}
|
|
|
|
# ── Backend WebSocket (realtime shared state + voice PCM) ──────
|
|
location ^~ /ws {
|
|
proxy_pass http://gmw_backend$uri$is_args$args;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection $connection_upgrade;
|
|
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;
|
|
proxy_buffering off;
|
|
proxy_read_timeout 86400s;
|
|
proxy_send_timeout 86400s;
|
|
}
|
|
|
|
# ── Backend oRPC (structured data RPCs over WebSocket + HTTP POST)
|
|
# Browser reaches this via partysocket (wss://…/trpc); SSR/RSC uses
|
|
# the fetch RPCLink (POST /trpc). Same path, same backend handler:
|
|
# oRPC's RPCHandler (HTTP) + ORPCWebSocketServer (WS) on :4001. ──
|
|
location ^~ /trpc {
|
|
proxy_pass http://gmw_backend$uri$is_args$args;
|
|
proxy_http_version 1.1;
|
|
# Upgrade headers required for the WebSocket transport; harmless for POST.
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection $connection_upgrade;
|
|
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;
|
|
proxy_buffering off;
|
|
proxy_read_timeout 86400s;
|
|
proxy_send_timeout 86400s;
|
|
}
|
|
|
|
# ── Next.js build assets — immutable, edge/shareable ───────────
|
|
location ^~ /_next/static/ {
|
|
proxy_pass http://gmw_next$uri$is_args$args;
|
|
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;
|
|
expires 1y;
|
|
add_header Cache-Control "public, immutable";
|
|
}
|
|
|
|
# ── Everything else → Next.js server (SSR) ──
|
|
location / {
|
|
proxy_pass http://gmw_next$uri$is_args$args;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Connection "";
|
|
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;
|
|
proxy_set_header X-Next-Prefetch $http_x_next_prefetch;
|
|
proxy_buffering off;
|
|
proxy_read_timeout 30s;
|
|
}
|
|
}
|
|
} |