In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how Nginx limits access frequency, download rate, and the number of concurrent connections. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
I. Overview of modules and instructions used to limit access frequency, concurrent connections, and download speed
Ngx_http_limit_req_module: the leaky bucket algorithm "leaky bucket" is used to limit the number of requests per unit time, that is, rate limit.
Ngx_http_limit_conn_module: used to limit the number of connections at the same time, that is, concurrency limit
Limit_rate and limit_rate_after: download speed settin
Leaky bucket algorithm (leaky bucket)
The idea of the algorithm is:
The water (request) is poured into the bucket from above and flows out from below (being processed).
Water that doesn't flow out in time is stored in a bucket (buffer) and flows out at a fixed rate.
The water overflows (discards) when the bucket is full.
The core of this algorithm is: cache requests, uniform processing, and redundant requests are discarded directly.
The Nginx speed limit by request rate module uses the leaky bucket algorithm, that is, it can forcibly ensure that the real-time processing speed of the request will not exceed the set threshold.
2. Limit the frequency of URL access requests
Http {... Limit_req_zone $binary_remote_addr zone=one:30m rate=20r/s; limit_req_zone $binary_remote_addr $uri zone=two:30m rate=20r/s; limit_req_zone $binary_remote_addr $request_uri zone=three:30m rate=20r/s; limit_req_status 444;... Server {... Limit_req zone=two burst=15 nodelay;...}}
Explanation:
Limit_req_zone $binary_remote_addr zone=one:30m rate=20r/s
$binary_remote_addr is a URL that restricts the same client ip address to different URL
Zone: zone domain name one to store session30M
Rate: requests per second
Limit_req_zone $binary_remote_addr $uri zone=two:30m rate=20r/s
$binary_remote_addr $uri is to restrict the same client ip address to the same URL
Zone: zone domain name two to store session30M
Rate: requests per second
Limit_req_zone $binary_remote_addr $request_uri zone=three:30m rate=20r/s
$binary_remote_addr $request_uri is to restrict the same client ip address to the same URL
Zone: zone domain name two to store session30M
Rate: requests per second
Limit_req zone=two burst=15 nodelay
Zone reference zone is two
Burst sets a buffer with a size of 15, and when a large number of requests (outbreaks) come in, access exceeds the above limit and can be placed in the buffer first.
Nodelay is usually used with burst. If nodelay is set, it will be returned directly when the access exceeds the frequency and the buffer is full. If set, all major requests will wait for queuing.
III. Limit on the number of concurrent connections
Case 1:
Http {... Limit_conn_log_level error; limit_conn_zone $binary_remote_addr zone=addr:10m; limit_conn_status 503;... Server {... Location / download/ {limit_conn addr 1; single client IP is limited to 1}.}
Case 2:
Http {limit_conn_zone $binary_remote_addr zone=perip:10m; limit_conn_zone $server_name zone=perserver:10m; server {... Limit_conn perip 10; # the number of connections between a single client ip and the server limit_conn perserver 100; # limit the total number of connections to the server}}
Fourth, limit the download speed
Location / download {limit_rate 128k;} # if you want to set the speed limit for the first 10m of downloading files, and then use the 128kb/s speed limit when it is larger than 10m, you can add the following content location / download {limit_rate_after 10m; limit_rate 128k;} Thank you for reading! This is the end of the article on "how to limit the access frequency, download rate and concurrent connections of Nginx". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.