EthioDeploy
DocsPricingDomainsBlogToolsChangelog

Blog/Fix deploy errors

"WebSocket connection failed" after deploy: proxies, wss and idle timeouts

BS
Brook SolomonPublished November 29, 2026
Share on XShare on LinkedIn
wss://

THE SHORT ANSWER

"WebSocket connection to 'wss://...' failed" after deploy means the handshake never reached your app or the app's answer never came back. Check four things in order. Use wss:// with the same host as the page, or a relative URL: browsers refuse ws:// from an https page. Make sure the proxy forwards the Upgrade and Connection headers; Nginx drops them unless you set them, while Traefik and Cloudflare pass them on their own. Serve the socket on the same port as your HTTP app, because hosts route one port. If connections open and then die after a minute or so, an idle timeout closed them: send pings every 25 to 30 seconds and reconnect on close. Platforms that sleep idle apps also close open sockets when they stop the app.

What does "WebSocket connection failed" mean?

A WebSocket starts as an ordinary HTTP request carrying Upgrade: websocket. The server has to answer 101 Switching Protocols; after that the same TCP connection carries WebSocket frames in both directions. Chrome prints this when the handshake gets anything else, or nothing:

WebSocket connection to 'wss://app.example.com/socket' failed:

The message often ends there, with no reason. Open the Network tab, filter by “WS” and click the request. The status code tells you which layer failed:

  • 101, then a close: the socket worked and something closed it later. See the timeout section.
  • 200 or an HTML page: the request reached a normal HTTP route, so a proxy dropped the Upgrade header.
  • 301 or 308: you connected to ws:// and the host redirects to HTTPS. WebSocket clients don't follow redirects.
  • 404: wrong path, or the socket server isn't attached to the HTTP server that got the request.
  • 502, 503 or no status: nothing answered at the address the proxy used.

A different error appears before any request is sent when an https page tries ws://:

SecurityError: Failed to construct 'WebSocket': An insecure WebSocket connection may not be initiated from a page loaded over HTTPS.

Quick checklist

What you seeLikely causeFix
SecurityError or mixed contentws:// hard-coded in the clientUse wss:// or build the URL from location
Works locally, fails on the serverClient still points at localhost or a second portSame host as the page, same port as the HTTP app
Status 200 or 400 instead of 101Proxy didn't forward Upgrade and ConnectionAdd the two proxy_set_header lines in Nginx
Drops after about 60 seconds of quietProxy idle timeoutPing every 25 to 30 seconds, or raise the timeout
Drops on every deploy, or at randomThe process or proxy restartedReconnect with backoff in the client

Is the client using the right URL?

Most “works locally” failures are the URL. In development the page is http://localhost:3000 and the socket is ws://localhost:3001, and both get copied into production. Three rules cover it:

  • Match the page's scheme. An https page needs wss://. Since the WebSocket constructor accepts http and https URLs and relative URLs, and converts them to ws and wss, you can skip the scheme logic entirely.
  • Use the page's host, or an env var set to the real API domain, never a hard-coded localhost.
  • Drop the extra port. Most hosts route one public port to one port in your app. A socket server listening on its own port is unreachable; attach it to the HTTP server instead.
// Browser: same host and scheme as the page
const ws = new WebSocket(new URL("/socket", location.href));

// Server (Node, ws package): share the HTTP server and its port
import http from "node:http";
import { WebSocketServer } from "ws";

const server = http.createServer(app);
const wss = new WebSocketServer({ server, path: "/socket" });
server.listen(process.env.PORT ?? 3000, "0.0.0.0");

If the socket lives on a different domain than the page, as with a separate API, the browser doesn't apply CORS to WebSockets. Your server sees an Origin header and should check it itself. A failure there is your own code rejecting the handshake.

How do you proxy WebSockets through Nginx?

Upgrade and Connection are hop-by-hop headers, so Nginx doesn't pass them to the backend. Without them your app sees an ordinary GET and answers 200 or 400, and the browser reports the handshake as failed. Nginx's own example:

http {
    map $http_upgrade $connection_upgrade {
        default upgrade;
        ''      close;
    }

    server {
        location / {
            proxy_pass http://127.0.0.1:3000;
            proxy_http_version 1.1;   # needed before nginx 1.29.7
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
            proxy_set_header Host $host;
            proxy_read_timeout 3600s;
        }
    }
}

The map sends Connection: upgrade only for requests that asked for one, so normal requests keep working. proxy_read_timeout is there because, per the docs, “the connection will be closed if the proxied server does not transmit any data within 60 seconds”. A chat that is quiet for a minute drops at exactly 60 seconds. Raise the timeout, or send pings so it never expires.

Traefik and Caddy proxy WebSockets without extra configuration. Cloudflare supports them on all plans as long as the record is proxied and the origin answers the upgrade.

Why does the connection close after a while?

Every layer between browser and app can close a connection that carries no data:

  • Nginx, after 60 seconds by default (proxy_read_timeout).
  • Cloudflare, after a period it doesn't publish. Its docs also say that when it releases new code it “may restart servers, which terminates WebSockets connections”.
  • Load balancers, corporate proxies and mobile networks, on timers you can't see.
  • Your own deploys and restarts, which end every connection to the old process.

So design for it: send a ping every 25 to 30 seconds, and reconnect when the socket closes. Socket.IO does both by default (the server pings every 25 seconds and the client reconnects). With the plain ws package, ping from the server and drop clients that stop answering:

wss.on("connection", (ws) => {
  ws.isAlive = true;
  ws.on("pong", () => { ws.isAlive = true; });
});

setInterval(() => {
  for (const ws of wss.clients) {
    if (!ws.isAlive) { ws.terminate(); continue; }
    ws.isAlive = false;
    ws.ping();
  }
}, 30_000);

On the client, reconnect in the close handler with a growing delay (1 s, 2 s, 4 s, capped at 30 s) so a restarting server isn't hit by every client at once.

What happens on EthioDeploy?

WebSockets work with no settings. Requests go through Cloudflare, then Traefik, then to your app on port 3000, and both layers pass the upgrade through. Things to get right:

  • Use wss://. Port 80 only redirects to HTTPS, so a ws:// connection gets a 301 and fails.
  • Serve the socket from the same process and port as your HTTP app ($PORT, which is 3000). Only that port is routed.
  • Expect a close on every deploy. When the new version passes its health check, traffic moves to it and the old container is stopped, which closes its sockets. Clients that reconnect land on the new version.

Traefik itself didn't cut idle sockets in our test: with the same Traefik version and default timeouts, a connection that sent nothing for 200 seconds stayed open. Cloudflare in front can still close quiet connections, so keep the ping.

On the Free plan, apps sleep after 30 minutes without traffic, and an open WebSocket doesn't count as traffic. Activity is read from the proxy's access log, which records a WebSocket request only when it ends. A page that opens one socket and then talks over it for an hour will see the app stop after 30 minutes and the socket close. The first handshake to a sleeping app wakes it but doesn't complete; the client's next reconnect gets through. Reconnect logic handles both cases. If your app depends on long-lived connections, Pro and Business apps don't sleep. More in the troubleshooting docs and Deploy an Express app.

Questions

Usually the client URL still points at localhost or a separate port, or uses ws:// on an https page. Build the URL from the page's own host, use wss://, and attach the socket server to the same HTTP server and port as the rest of the app.

proxy_set_header Upgrade $http_upgrade and proxy_set_header Connection "upgrade" (or a map that sets it only for upgrade requests), plus proxy_http_version 1.1 on Nginx older than 1.29.7. Raise proxy_read_timeout or send pings, since Nginx closes a proxied connection after 60 seconds without data.

A proxy closed it for being idle. Nginx does this after 60 seconds without data by default. Send a ping every 25 to 30 seconds from the server, and reconnect from the client when the socket closes.

Yes, on all plans, for proxied records. Cloudflare closes connections that carry no data for a while and can drop connections when it restarts servers, so clients should ping and reconnect.

No. Sleep is based on requests in the proxy's access log, and a WebSocket is logged only when it closes. A Free app with no other traffic stops after 30 minutes and its sockets close. Pro and Business apps don't sleep.

Sources

Checked on November 29, 2026:

  • nginx: WebSocket proxying
  • MDN: WebSocket() constructor
  • Cloudflare: WebSockets
  • Traefik: EntryPoints (respondingTimeouts)
  • Socket.IO: Server options
  • ws: detecting broken connections

Push a repo. Get a URL.

  • Deploy an Express app
  • ERR_TOO_MANY_REDIRECTS behind a proxy
  • CORS error after deploy
  • Pricing
Start free

Join the EthioDeploy Telegram

Release notes as they ship, plus deploy help from the team and other developers.

Join on Telegram
BS
WRITTEN BYBrook SolomonFounder, EthioDeploy

Brook Solomon founded EthioDeploy and builds its deploy pipeline, build servers and AI coding agent. The posts here come from errors seen in real deploys on the platform.

All posts by Brook →
On this page
  • What does "WebSocket connection failed" mean?
  • Quick checklist
  • Is the client using the right URL?
  • How do you proxy WebSockets through Nginx?
  • Why does the connection close after a while?
  • What happens on EthioDeploy?
  • Questions
  • Sources
0% read

Keep reading

  • Mixed Content: blocked

    Fix deploy errorsNov 29, 2026

    Mixed content blocked after moving to HTTPS: causes and fixes

    A mixed content error means the page loaded over HTTPS but asked for something over plain http://. Browsers block scripts, stylesheets, fetch() and XMLHttpRequest calls (Chrome: "This request has been blocked; the content must be served over HTTPS") and upgrade images, audio and video to https on their own. After a deploy the cause is usually one of three things: an http:// URL in your code or in an env var such as the API base URL, a backend behind a TLS-terminating proxy that thinks it runs on http and builds http:// links, or old http:// URLs saved in the database. Change the URLs to https:// or relative paths, make the framework trust X-Forwarded-Proto, and treat the upgrade-insecure-requests CSP directive as a stopgap.

  • Health check failed

    Fix deploy errorsNov 29, 2026

    Health check failed: app not listening on its port

    A deploy fails its health check when the platform starts the new version and gets no healthy answer in time. There are four reasons: nothing listens on the port the platform probes, the process exits, the app takes longer to start than the platform waits, or it answers the check path with an error status such as 404. Render logs "No open ports detected" and fails the deploy, Railway marks the deploy failed when the healthcheck path returns no 2xx within 300 seconds, Fly warns "The app is not listening on the expected address", and Heroku kills a web process that hasn't bound to $PORT within 60 seconds (R10). Read the log to see which of the four it is: then listen on 0.0.0.0 and $PORT, move slow work out of startup, or point the health check at a route that returns 200.

  • .python-version

    Fix deploy errorsNov 29, 2026

    Python version mismatch on deploy: SyntaxError, "requires a different Python" and failed wheels

    If your app works locally and the deploy fails with a SyntaxError on valid code, "Ignored the following versions that require a different python version", or a wheel that won't build, the server is running a different Python than you are. Check with python --version locally and in the build log, then pin the same minor version in a .python-version file containing just 3.12 (or whatever you use). Heroku, Render, uv and pyenv all read that file; runtime.txt is deprecated on Heroku. Nixpacks, which EthioDeploy uses, reads NIXPACKS_PYTHON_VERSION, .python-version and runtime.txt, knows only 3.7 to 3.13, and silently falls back to 3.12 for anything else. requires-python in pyproject.toml doesn't choose the interpreter on any of them except uv. With a Dockerfile, the FROM line decides.

EthioDeploy

Agentic first development and deployment, started in Ethiopia, built for developers everywhere.

Telegram community
Product
PricingAI coding agentAgent mode docsDomainsCLIFree backend hostingHosting in EthiopiaChangelog
Deploy guides
Next.jsNode.jsPythonSvelteKitTanStack StartAstroNuxtReact RouterHonoStrapiPayload CMSDjangoDjango + CeleryFastAPIFlaskStreamlitExpressNestJSSocket.IOLaravelRailsGoSpring BootASP.NET CoreTelegram botDiscord botWhatsApp botn8nLovableBoltReplitv0Google AI StudioBase44Firebase StudioClaude Code & Cursor
Compare
vs Herokuvs Vercelvs Rendervs Railwayvs Fly.iovs Netlifyvs KoyebHeroku alternativesVercel alternativesNetlify alternativesRender alternativesRailway alternativesFly.io alternativesReplit alternativesPythonAnywhere alternativesDigitalOcean App Platform alternativesGlitch alternatives
Resources
DocsBlogFree toolsAboutSupportContactllms.txt
© 2026 EthioDeployPay by card in USD or bank transfer in ETBTermsPrivacy