nginx limit the number of requests (ngx_http_limit_req_module) module nginx concat module echo nginx module nginx upsync module

WBOY
Release: 2016-07-29 08:55:00
Original
1247 people have browsed it

The previous article mainly writes about the function and use of the ngx_http_limit_conn_module module in nginx to limit the number of connections. Next, let’s write about the function and use of the ngx_http_limit_req_module module.

The ngx_http_limit_req_module module can limit the frequency of request processing through defined key values. In particular, it is possible to limit the frequency with which requests from a single IP address are processed. The limiting method is like a funnel, which processes a fixed number of requests per second and postpones excessive requests.

This module provides two configuration parameters, limit_req_zone and limit_req. Limit_req_zone can only be configured in the http{} section, while limit_req can be configured in the http{}, server{}, and location{} sections.


1. limit_req_zone

Syntax: limit_req_zone $variable z rate=rate;
Configuration section: http

This command sets a shared memory restriction domain to save the state parameters of the key value. In particular, the current quantity exceeding the request is saved. The value of the key is the specified variable (the control is not evaluated). Such as:

nginx rtmp module,nginx upload module,lua nginx module,fastdfs nginx module,nginx sticky module,nginx add module,nginx concat module,echo nginx module,nginx upsync modul

Note:
Using the $binary_remote_addr variable, the size of each status record can be reduced to 64 bytes, so that 1M of memory can save approximately 16,000 64-byte records

If the storage space of the restricted domain is exhausted, for For all subsequent requests, the server will return a 503 (Service Temporarily Unavailable) error

The speed can be set to the number of requests processed per second and the number of requests processed per minute. The value must be an integer, so if you need to process less than 1 per second request, 2 seconds to process a request, you can use 30r/m


2. limit_req

syntax: limit_req z burst=number [nodelay];
Configuration section: http, server, location

Set the corresponding shared memory limit domain and the maximum number of requests allowed to be processed. If the frequency of requests exceeds the value configured in the limit domain, request processing will be delayed so that all requests are processed at the defined frequency. Requests that exceed the frequency limit will be delayed until the number of delayed requests exceeds the defined threshold. At this time, the request will be terminated and a 503 (Service Temporarily Unavailable) error will be returned. The default value of this threshold is 0. For example:

Limit the frequency to no more than one request per second, and allow no more than 100 requests exceeding the frequency limit; if you do not want the exceeded requests to be delayed, you can use the nodelay parameter.

nginx rtmp module,nginx upload module,lua nginx module,fastdfs nginx module,nginx sticky module,nginx add module,nginx concat module,echo nginx module,nginx upsync modul


3. Configuration usage example

limit_req_zone $binary_remote_addr z rate=1r/s;
Mainly used to define variables, space names, and shared memory size.

limit_req z burst=100 nodelay;
It is mainly used to use the previously defined space to define the request frequency limit. Using nodelay means that you do not want the exceeded requests to be delayed.

nginx rtmp module,nginx upload module,lua nginx module,fastdfs nginx module,nginx sticky module,nginx add module,nginx concat module,echo nginx module,nginx upsync modul

Some IPs may not be restricted and a whitelist needs to be used.

Module address: https://yunpan.cn/cqSKP6BrJ2AeT Access password 4f50

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces the nginx limit request number (ngx_http_limit_req_module) module, including module and nginx content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!