Please use this template for troubleshooting questions.
My issue: I’m looking for a way to rate-limit connection attempts per second from a single source IP on a stream (TCP/TLS) listener — equivalent to what limit_req does for http. The stream module only offers limit_conn, which caps concurrent connections, not the rate of new attempts over time. Because of this, a client can perform repeated failed TLS handshakes (e.g., invalid/missing client certificate) in rapid succession without ever tripping limit_conn, since each failed handshake closes quickly and frees the slot immediately. Each attempt still costs real CPU (TCP accept + TLS negotiation + client-cert chain verification) before being rejected — a low-and-slow handshake-flood vector that neither limit_conn nor ssl_handshake_timeout mitigates.
Is there any existing way (including NGINX Plus) to achieve this, and if not, is bringing limit_req-style rate limiting to the stream module on any roadmap?
How I encountered the problem: We proxy a TLS-terminated, mutually-authenticated TCP protocol (MQTT) through the stream module with ssl_verify_client on. While reviewing our per-source-IP abuse protections, I noticed our http/WebSocket listener’s limit_req correctly throttles all attempts per IP regardless of success/failure, but the equivalent protection isn’t possible on the stream listener since limit_req doesn’t exist there.
Solutions I’ve tried:
Confirmed ngx_stream_limit_req_module does not exist in nginx (checked official docs and changelog — only ngx_stream_limit_conn_module is available for stream).
- Currently using
limit_conn(concurrency cap) plusssl_handshake_timeout 10sto bound per-handshake cost, but this doesn’t limit attempt frequency.
Version of NGINX or NGINX adjacent software (e.g. NGINX Gateway Fabric): nginx 1.31.2
Deployment environment: Docker container (Debian/trixie based image), nginx as a TLS-terminating TCP proxy in front of an MQTT broker.
Minimal NGINX config to reproduce your issue (preferably running on NGINX Playground | tech-playground.com for ease of debugging, and if not as a code block): (Tip → Run nginx -T to print your entire NGINX config to your terminal.)
NGINX access/error log: (Tip → You can usually find the logs in the /var/log/nginx directory.)