Nginx的請求限制

2021-09-24 20:49:25 字數 2007 閱讀 3428

連線頻率的限制 -limit_conn_module

請求頻率的研製 -limit_req_module

tcp三次握手,一次連線可以建立多次http請求

連線限制的語法

#語法1

#語法2

請求限制的語法

#語法1

#語法2

limit_conn_zone(連線限制) $binary_remote_addr zone=conn_zone:1m; 

limit_req_zone(請求限制) $binary_remote_addr(請求ip) zone=req_zone(名稱):1m(空間大小) rate=1r/s(一秒一次);

server

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html

#error_page 500 502 503 504 404 /50x.html;

location = /50x.html

# proxy the php scripts to apache listening on 127.0.0.1:80

##location ~ \.php$

# pass the php scripts to fastcgi server listening on 127.0.0.1:9000

##location ~ \.php$

# deny access to .htaccess files, if apache's document root

# concurs with nginx's one

##location ~ /\.ht

}

測試請求限制是否生效安裝 ab工具

1.啟動配置limit_req zone=req_zone

壓測ab -n 20 -c 20

如果生效會列印錯誤日誌如下

2.啟動配置limit_req zone=req_zone burst=3 nodelay;

同樣測試

ab -n 20 -c 20

此時有做延時,請求只有16個

3.配置連線限制limit_conn conn_zone 1方法同上

nginx的請求限制

總結 http請求是建立在一次tcp連線的基礎之上。一次tcp請求至少產生一次http請求。配置語法 示例 limit conn conn zone 1 同一時刻只允許乙個ip的請求過來。示例 說明 binary remote addr 客戶端位址,不用 remote addr,是因為 binary...

Nginx限制連線和請求

一.ngx http limit conn module 對同乙個ip server的連線數做限制.配置指令 limit conn zone 語法 limit conn zone variable zone name size 預設值 none 配置段 http veriable 常見取值 a.bi...

nginx限制請求之四 目錄進行IP限制

高可用服務設計之二 rate limiting 限流與降級 nginx限制請求之一 ngx http limit conn module 模組 nginx限制請求之二 ngx http limit req module 模組 nginx限制請求之三 nginx lua redis 對請求進行限制 n...