Nginx WebSocket Proxy Fails (400 / Connection Closed)
Missing `proxy_http_version 1.1` and `Upgrade` / `Connection` hop-by-hop headers.
Runs locally in browser
Free · No login
Independently Verified 2026-11-25
v4.1.0
Identifier: Nginx WebSocket Proxy Fails (400 / Connection Closed)
Platform: Nginx
Common Root Causes:
- Missing `proxy_http_version 1.1` and `Upgrade` / `Connection` hop-by-hop headers.
Interactive Diagnostic Checklist
Verified Solutions:
- Add `proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade";`.
Safe Diagnostic Command:
grep -rn "Upgrade" /etc/nginx/sites-enabled/
Warning: Verify configuration changes in staging or with dry-run flags (e.g. nginx -t) before reloading production services.
Technical Explanation
Missing `proxy_http_version 1.1` and `Upgrade` / `Connection` hop-by-hop headers. Recommended diagnostic: `grep -rn "Upgrade" /etc/nginx/sites-enabled/`. Remediation: Add `proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade";`.
Worked Examples
- Run `grep -rn "Upgrade" /etc/nginx/sites-enabled/` to verify root cause before applying the remediation.
Limitations & Assumptions
- Always verify configuration changes in staging or with dry-run flags (e.g. `nginx -t`) before reloading production services.
Source References & Verification
Resource ID: err-nginx-websocket-upgrade-failed · Independently verified: 2026-11-25