Serve HTTP and WebSocket with the Same Port and Path in Nginx
Polkadot and other Substrate-based chain nodes supports JSON RPC over HTTP and over WebSocket on ports 9933 and 9944 individually. However, according to the WebSocket handshake, we can determine if the client is requesting WebSocket or other HTTP resource by the header Upgrade: websocket. Here’s a little trick in Nginx to reverse proxy both 9933 (HTTP) and 9944 (WebSocket) with the same host, same port, and same path / location.