How to limit concurrent http requests with nginx? Like "php -S localhost:8000"

I tried but he responding status code to 503 (we need handle when other requests completed):

limit_conn_zone $binary_remote_addr zone=addr:1m;
limit_conn addr 1;

From nginx documentation,

To limit the number of connections:

Use the limit_conn_zone directive to define the key and set the parameters of the shared memory zone (the worker processes will use this zone to share counters for key values). As the first parameter, specify the expression evaluated as a key. In the second parameter zone, specify the name of the zone and its size:

limit_conn_zone $binary_remote_addr zone=addr:10m;

Use the limit_conn directive to apply the limit within the location {}, server {}, or http {} context. Specify the name of the shared memory zone as the first parameter, and the number of allowed connection per key as the second parameter:

location /download/ {
     limit_conn addr 1;

The number of connections is limited on an IP address basis because the $binary_remote_addr variable is used as a key.

Another way to limit the number of connections for a given server is by using the $server_name variable:

http {
    limit_conn_zone $server_name zone=servers:10m;

    server {
        limit_conn servers 1000;
  • You’ve just cited documentation and this still doesn’t resolve author's problem – Alexey Ten May 26 at 10:36
  • Yes. This is source not helping to me. – runtomaker May 27 at 15:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.