docs/Reverse proxy a WebSocket service
Updated 2026-106 min read

Reverse proxy a WebSocket service

When a local service speaks WebSocket (real-time chat, market feeds), the reverse proxy has to allow the protocol upgrade — otherwise the connection fails during the handshake.

1 The upstream project

First make sure the local WebSocket service runs on its own, for example listening on 127.0.0.1:8081:

Upstream project

2 Configure the proxy

Point the upstream at that service and enable the WebSocket upgrade:

{
  "listen": 8080,
  "server_name": "localhost",
  "location": [
    { "url": "/socket", "type": "proxy", "root": "http://127.0.0.1:8081", "websocket": true }
  ]
}

After saving and restarting, the frontend can talk over ws://localhost:8080/socket (or wss:// for an encrypted connection).

Things to watch

ItemRecommendation
Keep-aliveMake the local service send heartbeats so the proxy does not time the connection out
Path matchingThe WebSocket path must match the upstream path
HTTPSUse wss:// externally and let Fast-Https terminate TLS
Frequent disconnects are usually the idle timeout of the local service, or a firewall blocking the port.