Java常用中介軟體之 NGINX實現限流功能的官方文件說明
官方文件:http://nginx.org/en/docs/http/ngx_http_limit_req_module.html
Module ngx_http_limit_req_module
limit_req
|
The
ngx_http_limit_req_module
module (0.7.21) is used to limit the request processing rate per a defined key, in particular, the processing rate of requests coming from a single IP address. The limitation is done using the “leaky bucket” method.
ngx_http_limit_req_module
模組(0.7.21)用於限制每一個定義的金鑰的請求的處理速率,特別是從一個單一的IP地址的請求的處理速率。使用“漏桶演算法”完成限制。
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
Syntax:語法 | limit_req |
---|---|
Default: 預設 | — |
Context:內容(作用範圍) | http , server , location |
Sets the shared memory zone and the maximum burst size of requests. If the requests rate exceeds the rate configured for a zone, their processing is delayed such that requests are processed at a defined rate. Excessive requests are delayed until their number exceeds the maximum burst size in which case the request is terminated with an error. By default, the maximum burst size is equal to zero. For example, the directives
設定共享記憶體區域和請求的最大突發大小。如果請求速率超過了區域配置的速率,則會延遲其處理,以便以定義的速率處理該請求。過多的請求將被延遲,直到其數量超過最大突發大小為止,在這種情況下,該請求將因錯誤而終止 。預設情況下,最大突發大小等於零。例如,指令
limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s; server { location /search/ { limit_req zone=one burst=5; }
allow not more than 1 request per second at an average, with bursts not exceeding 5 requests.
If delaying of excessive requests while requests are being limited is not desired, the parameter
nodelay
should be used:
平均每秒最多允許不超過1個請求,並且突發不超過5個請求。
如果不需要在限制請求時延遲過多的請求,則應使用nodelay
引數:
limit_req zone=one burst=5 nodelay;
The
delay
parameter (1.15.7) specifies a limit at which excessive requests become delayed. Default value is zero, i.e. all excessive requests are delayed.There could be several
limit_req
directives. For example, the following configuration will limit the processing rate of requests coming from a single IP address and, at the same time, the request processing rate by the virtual server:
delay
引數(1.15.7),用於指定過多的請求延遲的限制。預設值為零,即所有多餘的請求都會延遲。
可能有幾個limit_req
指令。例如,以下配置將限制來自單個IP地址的請求的處理速度,同時限制虛擬伺服器的請求處理速度:
limit_req_zone $binary_remote_addr zone=perip:10m rate=1r/s; limit_req_zone $server_name zone=perserver:10m rate=10r/s; server { ... limit_req zone=perip burst=5 nodelay; limit_req zone=perserver burst=10; }
These directives are inherited from the previous configuration level if and only if there are no limit_req
directives defined on the current level.
當且僅當limit_req
當前級別上未定義任何指令時,這些指令才從先前的配置級別繼承。
Syntax: | limit_req_dry_run |
---|---|
Default: | |
Context: | http , server , location |
This directive appeared in version 1.17.1.
該指令出現在1.17.1版中
Enables the dry run mode. In this mode, requests processing rate is not limited, however, in the shared memory zone, the number of excessive requests is accounted as usual.
啟用空執行模式。在這種模式下,請求處理速率不受限制,但是,在共享記憶體區域中,過多請求的數量將照常計算。
Syntax: | limit_req_log_level |
---|---|
Default: | |
Context: | http , server , location |
This directive appeared in version 0.8.18.
該指令出現在版本0.8.18中。
Sets the desired logging level for cases when the server refuses to process requests due to rate exceeding, or delays request processing. Logging level for delays is one point less than for refusals; for example, if “
limit_req_log_level notice
” is specified, delays are logged with theinfo
level.
在伺服器由於速率超出而拒絕處理請求或延遲請求處理的情況下,設定所需的日誌記錄級別。延遲的記錄級別比拒絕的記錄級別少一個等級;例如,如果limit_req_log_level notice
指定“ ” ,則將延遲記錄為該info
級別。
Syntax: | limit_req_status |
---|---|
Default: | |
Context: | http , server , location |
This directive appeared in version 1.3.15.
該指令出現在1.3.15版中。
Sets the status code to return in response to rejected requests.
設定被拒絕的請求而返回響應的狀態程式碼。
Syntax: | limit_req_zone |
---|---|
Default: | — |
Context: | http |
Sets parameters for a shared memory zone that will keep states for various keys. In particular, the state stores the current number of excessive requests. The key
can contain text, variables, and their combination. Requests with an empty key value are not accounted.
設定共享記憶體區域的引數,該引數將保留各種鍵的狀態。特別是,狀態儲存了當前過多請求的數量。該key
可以包含文字,變數,他們的組合。具有空鍵值的請求不予考慮。
Prior to version 1.7.6, a
key
could contain exactly one variable.
在版本1.7.6之前,一個
key
只包含一個變數。
Usage example:
用法示例:
limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;
Here, the states are kept in a 10 megabyte zone “one”, and an average request processing rate for this zone cannot exceed 1 request per second.
A client IP address serves as a key. Note that instead of
$remote_addr
, the$binary_remote_addr
variable is used here. The$binary_remote_addr
variable’s size is always 4 bytes for IPv4 addresses or 16 bytes for IPv6 addresses. The stored state always occupies 64 bytes on 32-bit platforms and 128 bytes on 64-bit platforms. One megabyte zone can keep about 16 thousand 64-byte states or about 8 thousand 128-byte states.
在這裡,狀態保持在10兆位元組的區域“ one”中,並且該區域的平均請求處理速率不能超過每秒1個請求。
客戶端IP地址用作金鑰。注意,代替$remote_addr
,該 $binary_remote_addr
變數在這裡使用。$binary_remote_addr
對於IPv4地址,變數的大小始終為4個位元組,對於IPv6地址,變數的大小始終為16個位元組。儲存狀態在32位平臺上始終佔據64位元組,在64位平臺上始終佔據128位元組。一兆位元組的區域可以保留約1.6萬個64位元組狀態或約8000個128位元組狀態。
If the zone storage is exhausted, the least recently used state is removed. If even after that a new state cannot be created, the request is terminated with an error.
The rate is specified in requests per second (r/s). If a rate of less than one request per second is desired, it is specified in request per minute (r/m). For example, half-request per second is 30r/m.
如果區域儲存已用盡,則將刪除最近最少使用的狀態。如果即使在此之後仍無法建立新狀態,則請求將以error終止。
該速率以每秒請求數(r / s)指定。如果希望速率小於每秒一個請求,則以每分鐘請求數(r / m)來指定。例如,每秒0.5請求為30r / m。
The sync
parameter (1.15.3) enables synchronization of the shared memory zone.
sync
引數(1.15.3)開啟 同步 共享儲存區域。
The
sync
parameter is available as part of our
commercial subscription.
此外,作為我們的商業訂閱的一部分, 可以從1.17.7開始 使用API獲取或 重置每個此類共享儲存區 的 狀態資訊。
Additionally, as part of our commercial subscription, the status information for each such shared memory zone can be obtained or reset with the API since 1.17.7.
Embedded Variables
嵌入式變數
$limit_req_status
keeps the result of limiting the request processing rate (1.17.6):
使用PASSED
, DELAYED
, REJECTED
, DELAYED_DRY_RUN
, or REJECTED_DRY_RUN
保持限制請求處理率的結果(1.17.6)
相關文章
- Oracle 官方文件 結構說明Oracle
- 中介軟體-NginxNginx
- Linux下玩轉nginx系列(七)---nginx如何實現限流功能LinuxNginx
- [譯] React-Redux 官方 Hooks 文件說明ReactReduxHook
- .NET服務治理之限流中介軟體-FireflySoft.RateLimitMIT
- Express 文件(使用中介軟體)Express
- Redux 中介軟體的實現原理Redux
- Asp-Net-Core開發筆記:使用RateLimit中介軟體實現介面限流筆記MIT
- Ocer_軟體功能說明_簡體中文版
- 最常用的限流演算法以及如何在http中介軟體中加入流控演算法HTTP
- PHP 框架中介軟體實現PHP框架
- Nodejs 進階:Express 常用中介軟體 body-parser 實現解析NodeJSExpress
- 中介軟體之訊息中介軟體-pulsar
- 什麼是中介軟體?Linux常用中介軟體都有哪些?Linux
- [轉]MQ詳解以及各種訊息中介軟體說明MQ
- linux系統常用的中介軟體Linux
- 如何製作Java文件說明書Java
- Java多執行緒之---用 CountDownLatch 說明 AQS 的實現原理Java執行緒CountDownLatchAQS
- nginx之 nginx限流配置Nginx
- 軟體開發專案文件系列之五如何撰寫需求規格說明書
- 汪子熙趣味成語接龍的遊戲軟體使用文件說明遊戲
- Laravel 跨域功能中介軟體Laravel跨域
- 【ORACLE】Oracle常用SQL及重點功能說明OracleSQL
- 理解Laravel中介軟體核心實現原理Laravel
- .Net Core如何優雅的實現中介軟體
- Nginx中介軟體——從小白到入門Nginx
- 常用的MySQL中介軟體網址彙總MySql
- SpringGateway - Redis限流元件之Luau指令碼&Java實現SpringGatewayRedis元件指令碼Java
- MySQL中介軟體之ProxySQLMySql
- Android Jetpack - Fragment官方說明AndroidJetpackFragment
- Nginx的配置檔案說明Nginx
- ThinkPHP 6.0 管道模式與中介軟體的實現分析PHP模式
- 關於使用中介軟體實現返回 JSONJSON
- python爬蟲常用之Scrapy 中介軟體Python爬蟲
- 一文說通Dotnet Core的中介軟體
- 淺析 Laravel 官方文件推薦的 Nginx 配置LaravelNginx
- Koajs中介軟體之next(二)JS
- Koajs中介軟體之context(三)JSContext