reverse-proxy-websocket-debugging
Skill2 starsChanged 2 months agoMITView on GitHub
Use when WebSockets die behind a reverse proxy (close 1006).
In this repository58 other files it gives its agents.
- ad-hoc-script-verificationSkill
- architecture-diagramSkill
- blocked-page-recoverySkill
- cadquery-enclosure-designSkill
- canonical-thumbnailSkill
- circuit-designSkill
- competitor-news-monitorSkill
- component-alternativesSkill
- debugging-hermes-tui-commandsSkill
- docker-container-update-checkSkill
- document-to-action-itemsSkill
- docxSkill
- email-inbox-triageSkill
- embedded-porting-patternsSkill
- ephemeral-file-sharingSkill
- excalidrawSkill
- flash-game-researchSkill
- flutter-android-buildSkill
- flutter-content-renderingSkill
- github-code-reviewSkill
- githubSkill
- goatcounter-analyticsSkill
- google-oauth-file-pollSkill
- grounded-citationsSkill
- hermes-agent-skill-authoringSkill
- hermes-gateway-slash-commandSkill
- hermes-gateway-supervisionSkill
- jellyseerr-watch-suggestionsSkill
- maintained-fork-publishingSkill
- meeting-action-itemsSkill
- native-mcpSkill
- obsidian-mapsSkill
- pdf-flattenSkill
- pdfSkill
- pdf-surgical-editsSkill
- planSkill
- product-price-monitorSkill
- psp-developmentSkill
- psp-homebrew-testingSkill
- psp-prx-plugin-maintenanceSkill
- python-debugpySkill
- python-webapp-patternsSkill
- reddit-readingSkill
- retro-fansiteSkill
- rss-feedsSkill
- simplify-codeSkill
- sketchSkill
- skit-thumbnailSkill
- spikeSkill
- subagent-driven-developmentSkill
- test-driven-developmentSkill
- usb-device-enumerationSkill
- weekly-review-planningSkill
- wiki-media-asset-pipelineSkill
- windows-c-build-toolchainSkill
- windows-crash-forensicsSkill
- writing-plansSkill
- yt-dlp-anti-botSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 46
Never treat an automated-browser login as credential proof — verify in a real browser or server-side (e.g.
- Distinctive: line 49
Approval timeouts kill long sudo batches: if a mutating SSH batch times out at the approval gate, re-present the pending commands as a …
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Reverse-Proxy WebSocket Debugging
Symptom signature: pages load fine through the proxy, but WS-dependent features are dead. Browser console shows WebSocket Error then Closed WebSocket ... code: 1006 with reconnect loops; apps show banners like "This websocket connection has been closed. Are you using a reverse proxy?" (Crafty) or just silently no live data. Note: dashboard numbers may still appear — they can be server-rendered at page load, not WS evidence.
Root cause checklist (in order of likelihood)
- Upstream Host header rewritten by the proxy — Caddy's default for
reverse_proxy localhost:8443is to sendHost: localhost:8443upstream. Origin-checking backends (Tornadocheck_origin, Django Channels, Flask-SocketIO same-origin) compare the browser'sOrigin(public domain) against theHostthey see (now the dial address) → upgrade rejected with403 Cross origin websockets not allowed(Tornado). The browser turns the failed handshake into close 1006.- Caddy fix:
header_up Host {http.request.host}inside thereverse_proxyblock. - Nginx fix:
proxy_set_header Host $http_host;plus the upgrade headers below.
- Caddy fix:
- Upgrade headers not forwarded — Nginx needs explicit
proxy_http_version 1.1;,proxy_set_header Upgrade $http_upgrade;+Connection "upgrade";+X-Forwarded-Proto https;+X-Forwarded-For ...;. Caddy forwards upgrade headers automatically — if it still fails, suspect #1, not this. - Backend auth/origin policy — some apps validate a WS token cookie or require URL params; read the backend's WS handler source to see exactly what it checks before guessing.
Diagnosis drill
- Get the real WS URL: open the app in a browser and pull the console (browser_console). Apps often log the target, e.g. Crafty:
new WebSocket('wss://' + location.host + '/ws?...'). The frontend source is authoritative — grep it before blaming backend config. - Probe the handshake direct to the backend AND through the proxy with curl (no WS client library needed):
Through-proxy variant: same headers plus# direct backend (adjust scheme/port/params): 101 = healthy curl -sk -i --max-time 8 -H "Connection: Upgrade" -H "Upgrade: websocket" \ -H "Sec-WebSocket-Version: 13" -H "Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==" \ -H "Origin: https://<public-host>" "https://localhost:<backend-port>/ws?<params>"--resolve <public-host>:443:127.0.0.1with the real URL. Always--resolvethe real hostname — curlinghttps://localhostthrough a vhost-charged proxy dies in TLS (no cert for SNIlocalhost; looks like the proxy ate the request but it never reached HTTP). - Isolate Host-rewrite: resend through the proxy with
-H "Origin: https://localhost:<backend-port>". If THAT returns101 Switching Protocols, the proxy is rewriting Host upstream and the real-Origin check is what fails → apply theheader_up Hostfix. - Re-verify after the fix: real-Origin probe through the proxy →
101; browser console showsopened WebSocket connectionand no reconnect spam.
Pitfalls
- SPA login forms corrupt automation typing (React/Vue controlled inputs): browser_type can leave garbage or truncated values (username field ended up holding a framework token, password had 5 of 63 chars). Fix — set values via native setter + dispatch
input/changein one console JS line:
Never treat an automated-browser login as credential proof — verify in a real browser or server-side (e.g. DB hash check).const setVal=(el,v)=>{const d=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(el),'value');d.set.call(el,v);el.dispatchEvent(new Event('input',{bubbles:true}));el.dispatchEvent(new Event('change',{bubbles:true}));}; - Tornado XSRF on API login makes curl brute-forcing painful (cookie jar +
_xsrftoken dance); prefer browser or DB-backed verification. - Caddyfile edits: apply via write-through of the bind-mounted inode +
caddy validate+caddy reload(inode trap — see homelab-server-admin). - Approval timeouts kill long sudo batches: if a mutating SSH batch times out at the approval gate, re-present the pending commands as a short plan instead of silently retrying.
Worked case
Crafty Controller + Caddy (Aug 2026): full capture — commands, outputs, Caddyfile diff — in references/crafty-caddy-websocket.md.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

