What's new

Nginx config to limit each IP?

To limit each IP to a maximum of 30 connections per minute in Nginx, you can use the limit_conn_zone and limit_conn directives. Here's an example configuration:

Code:
http {
  limit_conn_zone $binary_remote_addr zone=addr:10m;
  
  server {
    ...
    
    location / {
      limit_conn addr 30;
      
      ...
    }
  }
}

Explanation:
  • limit_conn_zone defines the shared memory zone used to store connection tracking data. The $binary_remote_addr variable is used as the identifier for each client IP address, and the zone size is set to 10m (you can adjust the size to suit your needs).
  • limit_conn specifies the maximum number of connections per IP address within the specified shared memory zone. In this case, addr is the name of the connection zone defined earlier, and 30 is the maximum number of connections allowed.

This configuration will limit each client IP to a maximum of 30 connections per minute for all requests to the specified location. You can adjust the limits to suit your needs, and you can apply the limit_conn directive to other locations as needed.
 
Back
Top