標籤:ati 預設值 返回 cat 取值 span level 整數 作用
模組: ngx_http_limit_conn_module
作用: 根據定義的key限制並發串連數
配置樣本:
http { limit_conn_zone $binary_remote_addr zone=addr:10m; ... server { ... location /api/ { limit_conn addr 10; limit_conn_status 503; } }}
說明: 樣本中定義key(zone=addr)為addr,分配記憶體大小為10m(zone=addr:10m)(如果限制域的儲存空間耗盡了,對於後續所有請求,伺服器都會返回 503),同一個ip($binary_remote_addr)和伺服器串連超過10個(limit_conn addr 10)將會被攔截並返回503(limit_conn_status 503)錯誤碼
涉及指令:
limit_conn_zone
limit_conn
limit_conn_status
limit_conn_log_level
指令詳解:
limit_conn_zone文法: limit_conn_zone key zone=name:size;(設定限制規則、地區名稱及分配的記憶體大小)可配置地區: httpkey: 必選項;設定限制規則;取值可以是text文本、nginx變數或兩者的組合;執行個體中使用的nginx變數$binary_remote_addr表示根據每個ip限制並發name: 必選項; 自訂一個地區名稱; 任一字元串size: 分配記憶體的大小
limit_conn 文法: limit_conn zone number; (使用由limit_conn_zone定義的攔截規則, 並設定具體的限制串連數量)可配置地區: http, server, locationzone: 必選項; 由limit_conn_zone(zone=name)定義的名稱; 表示使用定義的哪個限制規則number: 必選項; 正整數; 表示具體的限制串連數量
limit_conn_status 文法: limit_conn_status code;預設值: 503可配置地區: http, server, location表示超出limit_req配置的請求數量後返回給用戶端的錯誤碼使用該指令最低版本 1.3.15
limit_conn_log_level 文法: limit_conn_log_level info | notice | warn | error;預設值: limit_conn_log_level error;可配置地區: http, server, location當伺服器拒絕處理由於速率超過或延遲請求處理而拒絕處理請求時,設定所需的日誌記錄層級。最低版本: 0.8.18
nginx並發串連控制模組ngx_http_limit_conn_module