How it works...
We create a shared memory space with the limit_conn_zone directive so that the connections can be tracked. We use $binary_remote_addr to track the remote (client) IP address and then name our zone conlimitzone. Finally, we allocate 10 MB by appending the zone name with :10m. This is the total space allocation, which is enough to track up to 160,000 concurrent IP addresses.
In our server block directive, we then use our zone by setting limit_conn to the zone name conlimitzone. This limit is then set to a total of 1 connection, which ensures that each unique IP address is only allowed to make a single connection.
Finally, we use limit_rate (as shown in our previous recipe) to limit the bandwidth per connection. As we have set ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access