Word; word-break: break-word; margin-top: 0px; margin-bottom: 0px; padding: 0px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); font-size: 15px; position: relative; color: rgba(0, 0, 0, 0.84); line-height: 2.2; font-family: nexzhu; text-align: justify; white-space: normal; background-color: rgb(255, 255, 255);">
设置网站的Nginx来增强网站的安全性
-酷库博客
-第1
张图片

在宝塔里面设置Ngixn非常简单。这里给出一些网站的保护措施,仅供参考。
1.禁止Scrapy等工具的抓取

if ($http_user_agent ~* (Scrapy|Curl|HttpClient)) {return 403;}

2.禁止指定UA及UA为空的访问

if ($http_user_agent ~ "WinHttp|WebZIP|FetchURL|node-superagent|java/|FeedDemon|Jullo|JikeSpider|Indy Library|Alexa Toolbar|AskTbFXTV|AhrefsBot|CrawlDaddy|Java|Feedly|Apache-HttpAsynCClient|UniversalFeedParser|ApacheBench|Microsoft URL Control|Swiftbot|ZmEu|oBot|jaunty|Python-urllib|lightDeckReports Bot|YYSpider|DigExt|HttpClient|MJ12bot|heritrix|EasouSpider|Ezooms|BOT/0.1|FlightDeckReports|Linguee Bot|^$" ) {return 403;}

3.禁止非GET|HEAD|POST方式的抓取

if ($request_method !~ ^(GET|HEAD|POST)$) {return 403;}

4.访问链接里含有 test 直接跳转地址

if ($request_uri ~* test=) {return 301 httPS://127.0.0.1;}


5.请求这些敏感词时跳转下载10g文件


if ($request_uri ~* "(.gz)|(")|(.tar)|(admin)|(.zip)|(.sql)|(.asp)|(.rar)|(function)|($_GET)|(eval)|(?PHP)|(config)|(')|(.bak)") {              return 301 http://lg-dene.fdcservers.net/10GBtest.zip;        }