Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Interpretation of limit configuration parameters in nginx

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly parses the configuration parameters related to limit in ngx_http_core_module, ngx_http_limit_conn_module and ngx_http_limit_req_module.

Limit_rate

Name default configuration scope official description Chinese interpretation module limit_ratelimit_rate 0 location, if in locationLimits 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. Specify the bytes that can be downloaded by the connection per second, which is mainly used to limit the bandwidth of individual requests: ngx_http_core_modulelimit_rate_afterlimit_rate_after, server, location, if in locationSets the initial amount after which the further transmission of a response to a client will be rate limited. Set how many bytes will start limit count, if less than this value, no speed limit ngx_http_core_modulelimit_except no default locationLimits 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. The Allowing the GET method makes the HEAD method also allowed setting will be restricted to method other than the specified http methods, allowing GET to automatically allow HEAD method ngx_http_core_module

Example

Location / downloads {limit_rate_after 1m; limit_rate 500k;} location / {proxy_pass http://localhost:3000; limit_except GET {deny all;}}

Limit_conn

Name default configuration scope official description Chinese interpretation module limit_conn has no default value, syntax limit_conn zone number;http, server, locationSets 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. Specify the maximum number of connections per key of a zone ngx_http_limit_conn_modulelimit_conn_zone has no default value, syntax limit_conn_zone key zone=name:size;httpSets 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. The first parameter is key, and the second parameter is to specify the shared memory size of zone and its storage metadata (key,current num of conns per key,zone size) NGX _ http_limit_conn_modulelimit_conn_log_levellimit_conn_log_level error;http, server, locationSets the desired logging level for cases when the server limits the number of connections. This directive appeared in version 0.8.18. Specifies the log print level ngx_http_limit_conn_module when limit is triggered

Example

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

Name default configuration scope official description Chinese interpretation module limit_req has no default value, syntax limit_req zone=name [burst=number] [nodelay]; http, server, locationSets 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. Specifies that the burst size of zone ngx_http_limit_req_modulelimit_req_zone has no default value, syntax limit_req_zone key zone=name:size rate=rate;httpSets 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. The first parameter specifies key, the second parameter specifies the zone name and the memory size of metadata, and the third parameter rate specifies the threshold of requests per unit time ngx_http_limit_req_modulelimit_req_log_levellimit_req_log_level error;http, server, locationSets 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. Specifies the log level ngx_http_limit_req_module that is printed when req limit is triggered

Example

Http {limit_req_zone $binary_remote_addr zone=myreqzone:10m limit_req_log_level warn; server {# # each ip has a limit of 10 connections # # normally a browser opens two or three connections to each host # # if triggered, it will return 503 # # nodelay to calculate directly, and then calculate limit_req zone=myreqzone burst=10 nodelay;}} without some preheating

The above is the whole content of the limit configuration parameters in nginx. You can discuss it in the message area below. Thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report