解讀nginx中l(wèi)imit配置參數(shù)
本文主要解析一下ngx_http_core_module、ngx_http_limit_conn_module以及ngx_http_limit_req_module中的limit相關(guān)配置參數(shù)。
limit_rate
名稱 | 默認(rèn)配置 | 作用域 | 官方說(shuō)明 | 中文解讀 | 模塊 |
---|---|---|---|---|---|
limit_rate | limit_rate 0; | http, server, location, if in location | Limits the rate of response transmission to a client. The rate is specified in bytes per second. The zero value disables rate limiting. The limit is set per a request, and so if a client simultaneously opens two connections, the overall rate will be twice as much as the specified limit. | 指定每秒該連接能下載的bytes,主要用來(lái)限制個(gè)別請(qǐng)求的帶寬 | ngx_http_core_module |
limit_rate_after | limit_rate_after 0; | http, server, location, if in location | Sets the initial amount after which the further transmission of a response to a client will be rate limited. | 設(shè)置多少bytes過(guò)后將啟動(dòng)limit計(jì)數(shù),如果小于此值則不限速 | ngx_http_core_module |
limit_except | 沒(méi)有默認(rèn)值 | location | Limits allowed HTTP methods inside a location. The method parameter can be one of the following: GET, HEAD, POST, PUT, DELETE, MKCOL, COPY, MOVE, OPTIONS, PROPFIND, PROPPATCH, LOCK, UNLOCK, or PATCH. Allowing the GET method makes the HEAD method also allowed | 設(shè)置除了指定的http methods外其他method將被限制,允許GET就自動(dòng)允許HEAD方法 | ngx_http_core_module |
實(shí)例
location /downloads { limit_rate_after 1m; limit_rate 500k; } location / { proxy_pass http://localhost:3000; limit_except GET { deny all; } }
limit_conn
名稱 | 默認(rèn)配置 | 作用域 | 官方說(shuō)明 | 中文解讀 | 模塊 |
---|---|---|---|---|---|
limit_conn | 沒(méi)有默認(rèn)值,語(yǔ)法 limit_conn zone number; | http, server, location | Sets the shared memory zone and the maximum allowed number of connections for a given key value. When this limit is exceeded, the server will return the error in reply to a request. | 指定一個(gè)zone的每個(gè)key最大連接數(shù) | ngx_http_limit_conn_module |
limit_conn_zone | 沒(méi)有默認(rèn)值,語(yǔ)法 limit_conn_zone key zone=name:size; | http | Sets parameters for a shared memory zone that will keep states for various keys. In particular, the state includes the current number of connections. The key can contain text, variables, and their combination. Requests with an empty key value are not accounted. | 第一個(gè)參數(shù)是key,第二個(gè)參數(shù)是指定zone及其存放元數(shù)據(jù)(key,current num of conns per key,zone size)的共享內(nèi)存大小 | ngx_http_limit_conn_module |
limit_conn_log_level | limit_conn_log_level error; | http, server, location | Sets the desired logging level for cases when the server limits the number of connections. This directive appeared in version 0.8.18. | 指定當(dāng)觸發(fā)limit的時(shí)候日志打印級(jí)別 | ngx_http_limit_conn_module |
實(shí)例
http { limit_conn_zone $binary_remote_addr zone=ips:10m; limit_conn_zone $server_name zone=servers:10m; limit_conn_log_level notice; server { # these limits apply to the whole virtual server limit_conn ips 10; # only 1000 simultaneous connections to the same server_name limit_conn servers 1000; } }
limit_req
名稱 | 默認(rèn)配置 | 作用域 | 官方說(shuō)明 | 中文解讀 | 模塊 |
---|---|---|---|---|---|
limit_req | 沒(méi)有默認(rèn)值,語(yǔ)法 limit_req zone=name [burst=number] [nodelay]; | 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. | 指定zone的burst大小 | ngx_http_limit_req_module |
limit_req_zone | 沒(méi)有默認(rèn)值,語(yǔ)法 limit_req_zone key zone=name:size rate=rate; | 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. | 第一個(gè)參數(shù)指定key,第二個(gè)參數(shù)指定zone名稱和元數(shù)據(jù)的內(nèi)存大小,第三個(gè)參數(shù)rate指定單位時(shí)間的請(qǐng)求數(shù)閾值 | ngx_http_limit_req_module |
limit_req_log_level | limit_req_log_level error; | http, server, location | 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. | 指定觸發(fā)req limit時(shí)打印的日志級(jí)別 | ngx_http_limit_req_module |
實(shí)例
http { limit_req_zone $binary_remote_addr zone=myreqzone:10m limit_req_log_level warn; server { ## 每個(gè)ip限定10個(gè)連接數(shù) ## 正常一個(gè)瀏覽器給每個(gè)host開兩到三個(gè)連接 ## 觸發(fā)的話會(huì)返回503 ## nodelay表示一上來(lái)就直接計(jì)算,不經(jīng)過(guò)一些預(yù)熱后再計(jì)算 limit_req zone=myreqzone burst=10 nodelay; } }
以上就是我們整理的nginx中l(wèi)imit配置參數(shù)的全部?jī)?nèi)容,大家可以在下方的留言區(qū)討論,感謝你對(duì)腳本之家的支持。
相關(guān)文章
Nginx服務(wù)器上搭建圖片緩存服務(wù)的基本配置解析
這篇文章主要介紹了Nginx服務(wù)器上搭建圖片緩存服務(wù)的基本配置解析,分別介紹了通過(guò)proxy_store模塊和proxy_cache模塊兩種方式的配置,需要的朋友可以參考下2016-04-04關(guān)于多級(jí)緩存使用(nginx本地緩存、JVM進(jìn)程緩存、redis緩存)
這篇文章主要介紹了關(guān)于多級(jí)緩存使用(nginx本地緩存、JVM進(jìn)程緩存、redis緩存),具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-08-08Nginx防盜鏈與服務(wù)優(yōu)化配置的全過(guò)程
由于Nginx本身的一些優(yōu)點(diǎn),輕量,開源,易用,越來(lái)越多的公司使用nginx作為自己公司的web應(yīng)用服務(wù)器,下面這篇文章主要給大家介紹了關(guān)于Nginx防盜鏈與服務(wù)優(yōu)化配置的相關(guān)資料,需要的朋友可以參考下2022-01-01實(shí)例詳解SpringBoot+nginx實(shí)現(xiàn)資源上傳功能
這篇文章主要介紹了SpringBoot+nginx實(shí)現(xiàn)資源上傳功能,由于小編最近在使用nginx放置靜態(tài)資源問(wèn)題,遇到很多干貨,特此分享到腳本之家平臺(tái),供大家參考,需要的朋友可以參考下2019-10-10Nginx 反向代理與負(fù)載均衡運(yùn)行小結(jié)
Nginx還支持對(duì)后端服務(wù)器進(jìn)行健康檢查,當(dāng)某個(gè)服務(wù)器不可用時(shí),Nginx會(huì)自動(dòng)將流量重定向到其他可用的服務(wù)器,這篇文章給大家分享Nginx 反向代理與負(fù)載均衡是如何運(yùn)行的,感興趣的朋友一起看看吧2024-03-03nginx中狀態(tài)統(tǒng)計(jì)的實(shí)現(xiàn)
本文主要介紹了nginx中狀態(tài)統(tǒng)計(jì)的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-04-04Nginx反向代理實(shí)現(xiàn)Vue跨域的示例
本文主要介紹了Nginx反向代理實(shí)現(xiàn)Vue跨域的示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-06-06Nginx配置參數(shù)中文說(shuō)明詳解(負(fù)載均衡與反向代理)
最近在看高性能Linux服務(wù)器構(gòu)建實(shí)戰(zhàn)的Nginx章節(jié),對(duì)其nginx介紹的非常詳細(xì),現(xiàn)把經(jīng)常用到的Nginx配置參數(shù)中文說(shuō)明摘錄和nginx做負(fù)載均衡的本人真實(shí)演示實(shí)例抄錄下來(lái)以便以后查看2020-03-03