Nginx Websocket – How to Limit Incoming Message Size

nginxwebsocket

In the JS WebSocket library, you can limit the maximum allowed incoming message size via the maxPayload option.

I'd like to impose this limit in my Nginx reverse proxy layer, before it gets to my application server.

Does Nginx have a similar concept? Does client_max_body_size (doc) apply to incoming websocket messages?

Best Answer

When nginx sees the 101 Switching Protocols response from the backend, it begins to treat the connection as an opaque tunnel and passes traffic back and forth without any further inspection. There is no directive that will limit any particular Websocket message in any way.