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 > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how nginx requests connection limit notes". In daily operation, I believe many people have doubts about how nginx requests connection limit notes. The editor consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "how nginx requests connection limit notes". Next, please follow the editor to study!
I have also written practical exercises about reptiles before: crawling Zhenai in gol.
At that time, when the concurrency is too large, the request will get stuck. In fact, this may be Zhenai's restrictions on requests and connections.
Crawlers and anti-crawlers are "attack while defending" technology, but our dear reptile engineers have always adhered to the principle of "only attack but no break". The website server has been restricting the crawler to avoid abnormal server traffic and excessive load, prevent malicious attacks from wasting bandwidth and resources, and even affect the normal operation of the business. Often the solution is to limit the number of connections and concurrency of the same IP. Today we will take a look at the connection frequency limit_conn_module and request frequency limit_req_module limit module of nginx.
The HTTP request is based on a TCP connection, and a TCP request generates at least one HTTP request.
Connection restrictions:
The syntax is as follows:
Syntax:limit_conn_zone key zone=name:size; Default:-Context:http
Limit_conn_zone: a space used to store the state of restricted connections
Key: key, which can be said to be a rule, is an identification of the customer server connection, for example, you can use the built-in variable-the client's ip
Zone: this is the name of this space, which needs to correspond to the configuration of location.
Size: it is the size of the application space.
Limit_conn directive: Syntax: limit_conn zone number;Default:-Context: http, server, location there is a prerequisite that limit_conn_zone must be defined under http before it can be referenced here.
The zone here is the name of the above zone, and number is the limited number of connections at the same time.
Request frequency limit:
Syntax: limit_req_zone key zone=name:size rate=rate;Default:-Context: http
The syntax is similar to the above, rate is a rate limit, how many in seconds.
Limit_req directive:
Syntax: limit_req zone=name [burst=number] [nodelay] Default:-Context: http,server,location
Burst=number, focus on this configuration, the meaning of burst burst. This configuration means to set a buffer with the size of number. When a large number of requests (outbreaks) come, requests that exceed the access frequency limit can be put into this buffer first, which acts as a speed limit for access.
Nodelay, if set, when the access frequency is exceeded and the buffer is full, the Service Temporarily Unavailable service is temporarily unavailable. If it is not set, all requests will be queued.
These two defaults do not need to be configured.
Examples of configurations are as follows:
$binary_remote_addr represents a binary IP address, and a binary ip address takes up 32 bytes on a 32-bit machine, so how much can 1m store? calculate that 1x1024x1024/32 = 32768, which means 32678 ip addresses can be stored, which saves 10 space than $remote_addr in a session.
Rate=1r/s says there can be only one request per second.
1 、
Comment out all the limit configurations under location and test them with the ab tool (stress testing tool):
Ab-n 10000-c1000 http://192.168.1.6/index.html
Where-n represents the total number of requests, and-c represents the number of requests at the same time.
All requests were successful after the request:
2 、
When only the limit_req zone=req_zone; comment is released, the same command is issued with the stress test tool ab:
You can see that only three requests were successful because the rate configured by req_zone is one request per second.
3 、
When only the limit_req zone=req_zone burst=3 nodelay; comments under location are released, continue to initiate the request:
As you can see, six were successful, three more than the last time. Burst=3 puts three requests into a buffer and waits for the next second to execute.
4 、
When only the limit_conn conn_zone 1; comment is released, use ab for testing. At this time, an ip can only establish one connection at a time.
At this point, the study on "how to request connection restriction notes by nginx" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.