Nginx Module Reference manual: HTTP Limit Requests module (http Limit Requests)

Source: Internet
Author: User
Keywords Http nginx requests requests Module
Tags binary compiled configure default default value example http location

These modules are all compiled into Nginx by default unless a module is manually specified to be excluded in configure.

This module allows you to limit the number of requests for a specified session or special case.

Sample Configuration

HTTP {limit_req_zone $binary _remote_addr zone=one:10m rate=1r/s ... location/search/{limit_req zone=one burst=5; }

Instructions

Limit_req_log_level

Syntax: Limit_req_log_level info|notice|warn|error
Default value: Warn
Working with Fields: HTTP
Specifies the level of logging.

Limit_req_zone

Syntax: Limit_req_zone $session _variable zone=name_of_zone:size rate=rate
Default value: None
Working with Fields: HTTP
The instruction describes the session-state storage area.
The instruction describes an area of the session state store, and the value of the session is based on the given variable, as in the following example:

Limit_req_zone $binary _remote_addr zone=one:10m rate=1r/s;

In this case, a 10MB is assigned to a zone named "One", which has an average query speed of up to 1 requests per second.
The session will track each user, but note that it replaces the variable $remote_addr, we are using $BINARY_REMOTE_ADDR to reduce the session size to 64 bytes, and a 1MB range can contain approximately 16,000 session states.
The speed can be set to the number of requests processed per second and the number of requests processed per minute, and the value must be an integer, so if you need to specify a request to process fewer than 1 requests per second, and 2 seconds to process a request, you can use "30r/m".
32,000 sessions can theoretically be processed when the session-state storage area is 1M, with each session size of 32 bytes.

Limit_req

Syntax: Limit_req=zone burst=burst [Nodelay]
Default value: None
Working with fields: HTTP, server, location
This instruction specifies the possible maximum request burst value (burst) for the Zone (zone), and if its value exceeds this number, the request is deferred so that the query is processed at a given speed. The extra requests will be deferred until their number is less than the burst value, in which case the request will get a "Service unavailable" (503) code with the default burst value of 0.
The following example:

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

Allows one user to process no more than 1 requests per second, which can handle up to 5 queries at the same time, and use the Nodelay parameter if additional requests outside the burst value are not available:

Limit_req Zone=one burst=5 Nodelay;
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.