天天看點

php 防止惡意灌水,Nginx禁止惡意User Agent采集網站

禁用一些User Agent可以節省一些流量也可以防止一些惡意的通路,尤其是部份搜尋引擎爬蟲,例如我們的網站就是一個地方性站點,沒有必要被一些國外的搜尋引擎爬蟲索引,都可以禁掉,具體操作如下:

php 防止惡意灌水,Nginx禁止惡意User Agent采集網站

1、編輯該檔案agent_deny.con:

# vi /usr/local/nginx/conf/agent_deny.conf

2、增加以下内容(示例):

if ($http_user_agent ~* (Scrapy|Curl|HttpClient)) {

return 404;

}

#空agent

if ($http_user_agent ~ ^$) {

return 404;

}

#請求方式限制

if ($request_method !~ ^(GET|HEAD|POST)$) {

return 403;

}

3、編輯檔案nginx.conf:

在server中引入agent_deny.conf

include agent_deny.conf;

有一些單詞中間有空格,是以兩邊需要使用雙引号,禁用了若幹個搜尋引擎爬蟲,還有幾個惡意灌水機等,可以分析日志根據情況屏蔽惡意的User Agent。

本文位址:http://www.it300.com/article-15358.html