Connection limits
What does a connection limit actually count?
Rate controls how often work arrives; concurrency controls how much work is in flight. Consider a report that occupies a backend for several seconds. Even a modest arrival rate can create many overlapping reports. Nginx HTTP connection limiting starts counting once a full request header has been read and the request is being handled. An idle HTTP/1.1 keepalive socket is not counted merely because it remains open. For HTTP/2 and HTTP/3, concurrent requests count separately, even on one multiplexed transport connection.
limit_conn_zone $binary_remote_addr zone=report_client:1m;limit_conn_zone $server_name zone=report_site:1m;The first zone tracks in-flight work per address and the second aggregates work by configured virtual-server name. Use separate zones for different policies; if multiple routes share a zone, they share its counters. Memory allocation alone imposes no concurrency restriction.
Protect a slow endpoint
location /reports/ { limit_conn report_client 2; limit_conn report_site 8; limit_conn_status 429; proxy_pass http://127.0.0.1:19090;}Both budgets must have room. Two overlapping reports from one client can pass; a third is refused until one finishes. Different clients can also hit the shared site limit of eight. These are sample bounds only. The policy returns an error instead of scheduling a queue of waiting requests. A rejected request does not occupy an admitted slot for its full backend processing time.
time | client | event | active after0 | A | start | A=1 B=01 | A | start | A=2 B=02 | A | reject | A=2 B=03 | B | start | A=2 B=14 | A | finish | A=1 B=15 | A | start | A=2 B=1Assume no other traffic and all allowed requests stay active until the specified finish. The site limit is not reached. The second client receives its own budget but still contributes to the site total. If the site already has eight active requests, even a new client with zero active requests is refused.
Combine rate and concurrency
location /reports/ { limit_req zone=search_rate burst=2 nodelay; limit_req_status 429; limit_conn report_client 2; limit_conn report_site 8; limit_conn_status 429; proxy_pass http://127.0.0.1:19090;}A service may need both controls. For rough capacity planning, if work takes an average of two seconds and starts at three requests per second, steady-state average concurrency is roughly six, provided the system is stable. This is not a peak bound; slow tails and burst patterns can raise concurrency. Set conservative limits and check service latency and saturation under approved conditions. The limit_conn module is not a substitute for worker connection limits, header timeouts, upstream connection pools or network protections.
Practice
A download route permits one active request per address and three for the site. Four different clients arrive while no requests are active. Predict the result if none finishes before the fourth arrival. Then explain how four HTTP/2 streams from one address would behave. Use the local lab to compare independent budgets, not to benchmark production.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Connection limits
Compare concurrent-request limits with arrival-rate limits and choose per-client and service-wide concurrency budgets.
An idle HTTP/1.1 keepalive socket has no active request. What does limit_conn count for it?
One HTTP/2 connection carries three overlapping requests. How many count for limit_conn?
A site limit is 8, with 8 active requests. A new client has none active. What happens?
Which situation most directly motivates a concurrent-request limit?
Why combine request-rate and connection limits?