In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
I. Overview of modules and instructions used to limit access frequency, concurrent connections, and download speed
Ngx_http_limit_req_module: used to limit the number of requests per unit time, i.e. rate limit. The leaky bucket algorithm "leaky bucket" 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 setting
Leaky bucket algorithm (leaky bucket)
The idea of the algorithm is:
The water (request) is poured into the bucket from above and flows from under the bucket (treated). The water that does not have time to flow is stored in the bucket (buffer) and flows out at a fixed rate; when the bucket is full, the water overflows (discarded). 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 limits the same client ip address to different URLzone: zone domain name one storage session30Mrate: number of requests per second
Limit_req_zone $binary_remote_addr $uri zone=two:30m rate=20r/s
$binary_remote_addr $uri limits the same client ip address to the same URLzone: zone domain name two storage session30Mrate: requests per second
Limit_req_zone $binary_remote_addr $request_uri zone=three:30m rate=20r/s
$binary_remote_addr $request_uri limits the same client ip address to the same URLzone: zone domain name two storage session30Mrate: requests per second
Limit_req zone=two burst=15 nodelay
The zone reference zone sets a buffer with a size of 15 for two,burst. When a large number of requests (outbreaks) come in, the 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;}
The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.
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.