Search code examples
nginxconnectionlimit

Nginx keeps hitting connection limit although I only use one connection


I configured nginx as followed (shortened):

http {
    limit_conn_zone $binary_remote_addr zone=conn_zone:10m;

    server {
        limit_conn conn_zone 50;
        limit_conn_log_level error;
        limit_conn_dry_run off;
        ...
    }

    ...
}

Now my website makes ~180 requests over 1 tcp connection. I already verified that only 1 connection is used. I put $connection to the nginx access log format. In the access log I can see that every of the 180 requests is made through the same connection ($connection id is always the same). My web browser shows the same, only 1 connection (id) is used.

In my nginx error.log I can see that the connection limit is hit for ~ 30 requests:

2024/07/01 14:57:12 [error] 1338808#1338808: *4560 limiting connections by zone "conn_zone", client: xxx, server: xxx, request: "GET /jsonapi.php/v1/xxx HTTP/2.0", host: "xxx", referrer: "xxx"

Now I dont get how the connection limit of 50 could be hit, when I only used one connection? How exactly does nginx count connections?


Solution

  • Finally found the problem, from the nginx docs:

    In HTTP/2 and HTTP/3, each concurrent request is considered a separate connection.