FAQ

Page Discussion Edit History

HttpLimitConnModule

Revision as of 19:33, 2 May 2012 by Admin (Talk | contribs)

(diff) 鈫 Older revision | Latest revision (diff) | Newer revision 鈫 (diff)

Contents

[edit] Synopsis

This module makes it possible to limit the number of concurrent connections for a defined key such as, for example, an ip address.

Example configuration

http {
  limit_conn_zone  $binary_remote_addr  zone=one:2m;
  limit_conn_log_level notice;
 
  server {
    location /download {
      limit_conn  one  1;
    }
  }
}

[edit] Directives

[edit] limit_conn

Syntax: limit_conn zone number
Default:
Context: http
server
location
Reference:limit_conn


Sets the maximum allowed number of connections for a given zone. When this limit is exceeded, the server will return a status error 503 (Service Temporarily Unavailable) in reply to the request.

Multiple limit directives for different zones can be used in the same context and each will apply.

Standard nginx inheritance applies. Lower contexts will inherit from higher context so long as there are no similar directives in the current context.

[edit] limit_conn_zone

Syntax: limit_conn_zone $variable zone = name : size
Default:
Context: http
Reference:limit_conn_zone


Sets the parameters for a zone that keeps state for various keys. This state stores the current number of connections in particular. The key is the value of the specified variable. Example usage:

    limit_conn_zone $binary_remote_addr zone=addr:10m;

Here, an IP address of the client serves as a key. Note that instead of $remote_addr, the $binary_remote_addr variable is used here. The length of the $remote_addr variable's value can range from 7 to 15 bytes, and the stored state occupies either 32 or 64 bytes of memory on 32-bit platforms, and always 64 bytes on 64-bit platforms. The length of the $binary_remote_addr variable's value is always 4 bytes, and the stored state always occupies 32 bytes on 32-bit platforms, and 64 bytes on 64-bit platforms. One megabyte zone can keep about 32 thousand 32-bit states, and about 16 thousand 64-byte states. If the storage for a zone is exhausted, the server will return error 503 (Service Temporarily Unavailable) to all further requests.

[edit] limit_conn_log_level

Syntax: limit_conn_log_level info | notice | warn | error
Default: error
Context: http
server
location
Appeared in: 0.8.18
Reference:limit_conn_log_level


Sets the error log level used when a connection limit is reached.

[edit] References

Original Documentation