In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Because there are often rush-buying services in business requirements, current-limiting errors need to be carried out at the front end of the load balancer. This paper is also applicable to prevent CC.
Limit_req_zone $server_name zone=sname:10m rate=1r/s; # restricts the server to access only once per second # limit_req_zone $binary_remote_addr zone=one:3m rate=1r/s; # restricts IP, only once per second # limit_req_zone $binary_remote_addr $uri zone=two:3m rate=1r/s; # restricts IP and path without parameters, # limit_req_zone $binary_remote_addr $request_uri zone=thre:3m rate=1r/s # restrict IP and path with parameters server {listen 80; server_name www.abc.com; location / {include host/proxy.cnf; proxy_pass http://backend;} location / api/createOrder {limit_req zone=sname; # without bursts, there can only be one normal request for limit_req_status 503 # set the returned status code to 503 # limit_req zone=sname burst=5 nodelay; # the maximum concurrency is 5, and real-time processing include host/proxy.cnf; proxy_pass http://backend; error_page 503 = 200 / 50x.html # it's important to send the error status code 503 and return the result as 200} location = / 50x.html {if ($http_user_agent ~ * "mobile | android | iPhone | iphone | ios | iOS") {# default_type application/json; return 200' {"msg": "activity is too hot, please try again later!", "data": {}, "code":-1}' # set the error message returned by the mobile terminal to display} root html; # if it is the PC side, return a HTML page}}
Important: under normal circumstances, if the current limit is set, the status code of 503 is returned, which is not recognized by the client even if you return JSON data on the mobile end. At this time, you can skillfully use error_page 403 = 200 / 50x.htl; set the status code to 200
The above only uses ngx_limit_req_module, but you can also use the ngx_limit_conn_module module.
Above reference: https://gist.github.com/simlegate/75b18359316cc33d8e20
In particular, if some consulting websites are targeted by crawlers, the server may be dried to death by crawlers (this is the case with small websites).
So what do we do? we can use variables to do it.
# Global configuration limit_req_zone $spider zone=spider:60m rate=200r/m; # limit crawlers to run 200 times per minute # limit_req zone=spider burst=5 nodelay;if in a server ($http_user_agent ~ * "spider | bot") {set $spider $http_user_agent; # set variable, enter here and set speed limit}
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.