FAQ

Page Discussion History

Difference between revisions of "HttpLimitReqModule"

(Added link to the original documentation)
(Directives)
Line 23: Line 23:
  
 
= Directives =
 
= Directives =
'''Syntax:''' ''limit_req_log_level '''info|notice|warn|error'''''
 
  
'''Default:''' ''warn''
+
== limit_req_log_level ==
 
+
<include wikitext nopre src="http://wiki.nginx.org/nginx.org/ngx_http_limit_req_module/limit_req_log_level.txt" />
'''Context:''' ''http''
+
  
 
Controls the log level of the rejected requests. Delayed requests are logged at the next less severe level, though, for example when limit_req_log_level is set to "error", delayed requests are logged at "warn".
 
Controls the log level of the rejected requests. Delayed requests are logged at the next less severe level, though, for example when limit_req_log_level is set to "error", delayed requests are logged at "warn".
  
 
+
== limit_req_zone ==
'''Syntax:''' ''limit_req_zone '''$session_variable''' zone='''name_of_zone''':'''size''' rate='''rate'''''
+
<include wikitext nopre src="http://wiki.nginx.org/nginx.org/ngx_http_limit_req_module/limit_req_zone.txt" />
 
+
'''Default:''' ''none''
+
 
+
'''Context:''' ''http''
+
  
 
The directive describes the area, which stores the state of the sessions. The values of the sessions is determined by the given variable. Example of usage:
 
The directive describes the area, which stores the state of the sessions. The values of the sessions is determined by the given variable. Example of usage:
Line 50: Line 44:
 
The speed is set in requests per second or requests per minute. The rate must be an integer, so if you need to specify less than one request per second, say, one request every two seconds, you would specify it as "30r/m".
 
The speed is set in requests per second or requests per minute. The rate must be an integer, so if you need to specify less than one request per second, say, one request every two seconds, you would specify it as "30r/m".
  
'''Syntax:''' ''limit_req zone='''zone''' burst='''burst''' [nodelay]''
+
== limit_req_zone ==
 
+
<include wikitext nopre src="http://wiki.nginx.org/nginx.org/ngx_http_limit_req_zone_module/limit_req_zone.txt" />
'''Default:''' ''none''
+
 
+
'''Context:''' ''http, server, location''
+
  
 
The directive specifies the zone ('''zone''') and the maximum possible bursts of requests (burst). If the rate exceeds the demands outlined in the zone, the request is delayed, so that queries are processed at a given speed. Excess requests are delayed while their number does not exceed a specified number of bursts. If the number of waiting requests exceed burst, the request is completed with the code 503 "Service Temporarily Unavailable". By default, the burst is zero.
 
The directive specifies the zone ('''zone''') and the maximum possible bursts of requests (burst). If the rate exceeds the demands outlined in the zone, the request is delayed, so that queries are processed at a given speed. Excess requests are delayed while their number does not exceed a specified number of bursts. If the number of waiting requests exceed burst, the request is completed with the code 503 "Service Temporarily Unavailable". By default, the burst is zero.

Revision as of 15:45, 30 April 2012

Contents

Synopsis

This module allows you to limit the number of requests for a given session, or as a special case, with one address.

Restriction done using leaky bucket.

Example Configuration

http {
    limit_req_zone  $binary_remote_addr  zone=one:10m   rate=1r/s;
 
    ...
 
    server {
 
        ...
 
        location /search/ {
            limit_req   zone=one  burst=5;
        }

Directives

limit_req_log_level

ERROR in secure-include.php: could not read the given src URL http://wiki.nginx.org/nginx.org/ngx_http_limit_req_module/limit_req_log_level.txt

Controls the log level of the rejected requests. Delayed requests are logged at the next less severe level, though, for example when limit_req_log_level is set to "error", delayed requests are logged at "warn".

limit_req_zone

ERROR in secure-include.php: could not read the given src URL http://wiki.nginx.org/nginx.org/ngx_http_limit_req_module/limit_req_zone.txt

The directive describes the area, which stores the state of the sessions. The values of the sessions is determined by the given variable. Example of usage:

limit_req_zone  $binary_remote_addr  zone=one:10m   rate=1r/s;

In this case, the session state is allocated 10MB as a zone called "one", and the average speed of queries for this zone is limited to 1 request per second.

The sessions are tracked per-user in this case, but note that instead of the variable $remote_addr, we've used the variable $binary_remote_addr, reducing the size of the state to 64 bytes. A 1 MB zone can hold approximately 16000 states of this size.

The speed is set in requests per second or requests per minute. The rate must be an integer, so if you need to specify less than one request per second, say, one request every two seconds, you would specify it as "30r/m".

limit_req_zone

ERROR in secure-include.php: could not read the given src URL http://wiki.nginx.org/nginx.org/ngx_http_limit_req_zone_module/limit_req_zone.txt

The directive specifies the zone (zone) and the maximum possible bursts of requests (burst). If the rate exceeds the demands outlined in the zone, the request is delayed, so that queries are processed at a given speed. Excess requests are delayed while their number does not exceed a specified number of bursts. If the number of waiting requests exceed burst, the request is completed with the code 503 "Service Temporarily Unavailable". By default, the burst is zero.

For example, the directive

limit_req_zone  $binary_remote_addr  zone=one:10m   rate=1r/s;
 
    server {
        location /search/ {
            limit_req   zone=one  burst=5;
        }

allows a user no more than 1 request per second on average, with bursts of no more than 5 requests.

If delaying excess requests within a burst is not necessary, you should use the option nodelay:

            limit_req   zone=one  burst=5  nodelay;

References

Original Documentation