Nginx module ngx_http_limit_req_module request processing module usage

Source: Internet
Author: User

Nginx module ngx_http_limit_req_module request processing module usage

In the previous article (), we talked about the ngx_http_limit_conn_module module to limit the number of concurrent connections. How can we limit the number of requests? This requires the ngx_http_limit_req_module module. This module can limit the frequency of request processing by defining key values. In particular, you can limit the frequency of processing requests from a single IP address. The method of restriction is like a funnel. The number of requests processed per second is fixed, and too many requests are postponed. To prevent DDOS attacks at the application layer.
Ngx_http_limit_req_module is a new module added after version 0.7.21. It is installed by default.

Limit_req_zone
Syntax: limit_req_zone $ variable zone = name: size rate = rate;
Default Value :-
Environment: http
Http {
Limit_req_zone $ binary_remote_addr zone = req_one: 10 m rate = 1r/s;

...

Server {

...

Location/search /{
Limit_req zone = req_one burst = 5;
} Note: A request restriction group is defined. The group name is req_one and the shared memory is 10 MB. The single base is calculated as $ binary_remote_addr, and the processing method is once per second.
If the storage space of the restricted domain is exhausted, the server will return the default 503 (Service Temporarily Unavailable) Error for all subsequent requests.

Limit_req
Syntax: limit_req zone = name [burst = number] [nodelay];
Default Value :-
Environment: http, server, location
Sets the maximum number of requests allowed to be processed by the corresponding restricted domain. If the request frequency exceeds the value configured in the restricted domain, request processing will be delayed, so 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, the request will be terminated and the default 503 (Service Temporarily Unavailable) error will be returned. The default value of this threshold is 0.
If you do not want to delay connections that exceed the limit, you can keep up with the nodelay parameter later.
The above example: limit_req zone = req_one burst = 5 nodelay;

Limit_req_log_level
Syntax: limit_req_log_level info | notice | warn | error;
Default Value: limit_req_log_level error;
Environment: http, server, location
This command is added after version 0.8.18.
Set the desired log level. The default value is the error level. When the server rejects or delays request processing because of the high frequency, you can write down the corresponding level of logs. The Log Level of the delayed record is one lower than that of the rejected log level. For example, if "limit_req_log_level notice" is set, the delayed log level is info.

Limit_req_status
Syntax: limit_req_status code;
Default Value: limit_req_status 503;
Environment: http, server, location
This command is added after version 1.3.15.
Sets the response code for a request rejection. The default value is 503.

Deployment of Nginx + MySQL + PHP in CentOS 6.2

Build a WEB server using Nginx

Build a Web server based on Linux6.3 + Nginx1.2 + PHP5 + MySQL5.5

Performance Tuning for Nginx in CentOS 6.3

Configure Nginx to load the ngx_pagespeed module in CentOS 6.3

Install and configure Nginx + Pcre + php-fpm in CentOS 6.4

Nginx installation and configuration instructions

Nginx log filtering using ngx_log_if does not record specific logs

Nginx details: click here
Nginx: click here

This article permanently updates the link address:

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.