In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
This article describes the configuration in which Nginx forbids specified UA access.
UA, or Http User Agent, uses the built-in variable $http_user_agent in Nginx to indicate that this information is sent to webserver as part of request header. Therefore, for webserver, one way to prohibit access is to judge the UA.
Prohibit search engine crawlers
Because, you know, I don't really want crawlers like Baidu to come to my website, so I use if to judge UA in Nginx:
If ($http_user_agent ~ * "qihoobot | Baidu | Baiduspider | Baiduspider-image | Baiduspider-video | Baiduspider-news | Baiduspider-favo | Baiduspider-cpro | Baiduspider-ads | Baiduboxapp | YisouSpider | EasouSpider | YodaoBot | YoudaoBot | Sosospider | Sogou | ^ $") {return 444;}
Prohibit downloading tools
If ($http_user_agent ~ * "Scrapy | HttpClient | Curl | Wget | Idm | Aria2 | Axel | Thunder | Youtube-dl | Movgrab | rtorrent | ctorrent | Transmission-cli | vuze") {return 444;}
Access to domestic browsers is prohibited
If ($http_user_agent ~ * | 360SE | 360EE | 2345Explorer | maxthon | sogou | qiyu | green | qq | qqbrowser | tt | liebao | lbbrowser | tao | taobao | coolnovo | saayaa | mi | xiaomi | baidu | yandex | wechat | weibo | douban | suning | iqiyi | alipay | ali-ap | ali-ap-pd | ali-am | ali-tb | ali-tb-pd | ali-tb-pd | ali-tb-pd ") {ali-tm 444;}
Disable access to the specified system
There are also some domestic systems, such as aliyun os, which I also want to ban:
If ($http_user_agent ~ * "yunos") {return 444;}
Conclusion
As you can see from the above, to judge UA, the rule is:
If ($http_user_agent ~ * "UA keyword") {.}
However, the disadvantage of this method is obvious, because UA is too easy to forge, but it is OK to guard against requests without forgery (such as domestic search crawlers). Of course, there are some more reliable ways, such as the verification of session.
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.