本文主要解析一下ngx_http_core_module、ngx_http_limit_conn_module以及ngx_http_limit_req_module中的limit相關配置參數。
limit_rate
名稱 | 默認配置 | 作用域 | 官方說明 | 中文解讀 | 模塊 |
---|---|---|---|---|---|
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,主要用來限制個別請求的帶寬 | 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. | 設置多少bytes過后將啟動limit計數,如果小于此值則不限速 | ngx_http_core_module |
limit_except | 沒有默認值 | 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 | 設置除了指定的http methods外其他method將被限制,允許GET就自動允許HEAD方法 | ngx_http_core_module |
實例
location /downloads { limit_rate_after 1m; limit_rate 500k; } location / { proxy_pass http://localhost:3000; limit_except GET { deny all; } }
limit_conn
名稱 | 默認配置 | 作用域 | 官方說明 | 中文解讀 | 模塊 |
---|---|---|---|---|---|
limit_conn | 沒有默認值,語法 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. | 指定一個zone的每個key最大連接數 | ngx_http_limit_conn_module |
limit_conn_zone | 沒有默認值,語法 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. | 第一個參數是key,第二個參數是指定zone及其存放元數據(key,current num of conns per key,zone size)的共享內存大小 | 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. | 指定當觸發limit的時候日志打印級別 | ngx_http_limit_conn_module |
新聞熱點
疑難解答