# Nginx反爬蟲攻略:禁止某些User Agent抓取網站
我們都知道網絡上的爬蟲非常多,有對網站收錄有益的,比如百度蜘蛛(Baiduspider),也有不但不遵守robots規則對服務器造成壓力,還不能為網站帶來流量的無用爬蟲,比如宜搜蜘蛛(YisouSpider)(最新補充:宜搜蜘蛛已被UC神馬搜索收購!所以本文已去掉宜搜蜘蛛的禁封!==>相關文章)。最近發現nginx日志中出現了好多宜搜等垃圾的抓取記錄,于是整理收集了網絡上各種禁止垃圾蜘蛛爬站的方法,在給自己網做設置的同時,也給各位站長提供參考。
進入到nginx安裝目錄下的conf目錄,將如下代碼保存為`agent_deny.conf`
`# cd /usr/local/nginx/conf`
`# vi agent_deny.conf`
~~~html
#禁止Scrapy等工具的抓取
if ($http_user_agent ~* (Scrapy|Curl|HttpClient)) {
return 403;
}
#禁止指定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|YandexBot|FlightDeckReports|Linguee Bot|^$" ) {
return 403;
}
#禁止非GET|HEAD|POST方式的抓取
if ($request_method !~ ^(GET|HEAD|POST)$) {
return 403;
}
~~~
然后,在網站相關配置中的 server段插入如下代碼:
`include agent_deny.conf;`
保存后,執行如下命令,平滑重啟nginx即可:
`/usr/local/nginx/sbin/nginx -s reload`
測試
使用curl -A 模擬抓取即可,比如:
curl\-I\-A'YYSpider'www.test.com
模擬UA為空的抓取:
curl\-I\-A' 'www.test.com
模擬百度蜘蛛的抓取:
curl -I -A 'Baiduspider' www.test.com
## 附錄:UA收集
~~~html
FeedDemon 內容采集
BOT/0.1 (BOT for JCE) sql注入
CrawlDaddy sql注入
Java 內容采集
Jullo 內容采集
Feedly 內容采集
UniversalFeedParser 內容采集
ApacheBench cc攻擊器
Swiftbot 無用爬蟲
YandexBot 無用爬蟲
AhrefsBot 無用爬蟲
YisouSpider 無用爬蟲(已被UC神馬搜索收購,此蜘蛛可以放開!)
jikeSpider 無用爬蟲
MJ12bot 無用爬蟲
ZmEu phpmyadmin 漏洞掃描
WinHttp 采集cc攻擊
EasouSpider 無用爬蟲
HttpClient tcp攻擊
Microsoft URL Control 掃描
YYSpider 無用爬蟲
jaunty wordpress爆破掃描器
oBot 無用爬蟲
Python-urllib 內容采集
Indy Library 掃描
FlightDeckReports Bot 無用爬蟲
Linguee Bot 無用爬蟲
~~~
參考:[http://zhangge.net/4458.html](http://zhangge.net/4458.html)
- (一)服務器架構
- ECS
- (二)寶塔安裝
- 寶塔的webhook使用方法
- (三)配置更改
- php-fpm.conf
- proxy.conf
- nginx.conf
- (四)運維日志
- nginx日志
- nginx錯誤日志
- open socket
- fpm日志
- php-fpm錯誤日志
- seems busy
- slow.log
- 站點日志
- dyhjw.log
- 站點錯誤日志
- dyhjw.error.log
- 499錯誤
- recv()
- recv() failed
- recv() failed-第3種
- no live upstreams
- upstream prematurely
- cache_file_has_too_long_header
- FastCGI sent in stderr
- directory index of is forbidden
- recv() failed-第4種
- (五)站點配置
- appapi配置
- 用到redis的網站
- workman不能運行
- 快訊啟動
- dyhjw偽靜態
- (六)其他問題
- php-5.6重新啟動報錯
- 掛載盤命令
- 服務器怎么增加黑名單不讓指定IP登錄
- (七)自定義頁面
- 自定義404頁面
- 自定義502頁面
- (八)問題
- 負載均衡的文件在哪里
- 站點的負載均衡服務器文件在哪里
- 其他知識
- Nginx--keepalive的配置
- Nginx反爬蟲攻略:禁止某些User Agent抓取網站
- php腳本執行時間配置
- 運維記錄