8

我的服务器上有一个 http 洪水,不是那么多查询,但无论如何。日志中的查询

95.55.237.3 - - [06/Sep/2012:14:38:23 +0400] "GET / HTTP/1.0" 200 35551 "-" "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US)" "-" | "-" 93.78.44.25 - - [06/Sep/2012:14:38:23 +0400] "GET / HTTP/1.0" 200 36051 "-" "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-美国)" "-" | "-" 46.118.112.3 - - [06/Sep/2012:14:38:23 +0400] "GET / HTTP/1.0" 200 35551 "-" "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-美国)" "-" | “——”

我在 nginx 配置中尝试了这个过滤器

server {
    .....
    set $add 1;
    set $ban '';

###### Rule 1 ########
if ($http_referer = '-' ) {
    set $ban $ban$add;
}
if ($request_uri = '/') {
    set $ban $ban$add;
}

if ($http_user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US)') {
    set $ban $ban$add;
}

if ($ban = 111) {
    return 444;
}
######################
......
}

但仍然 bot 查询得到 200 OK。有人可以帮忙吗?

4

3 回答 3

34

尝试在配置中添加类似以下指令以防止 http 泛滥:

http {
  limit_conn_zone $binary_remote_addr zone=conn_limit_per_ip:10m;
  limit_req_zone $binary_remote_addr zone=req_limit_per_ip:10m rate=5r/s;

  server {
    limit_conn conn_limit_per_ip 10;
    limit_req zone=req_limit_per_ip burst=10 nodelay;
  }
} 

有关更多信息,请参阅http://nginx.org/en/docs/http/ngx_http_limit_conn_module.htmlhttp://nginx.org/en/docs/http/ngx_http_limit_req_module.html

有以下所有指令http://nginx.org/en/docs/http/ngx_http_core_module.html#limit_rate

注意: http: //www.botsvsbrowsers.com/details/504401/index.html说上述用户代理不是已知的机器人

于 2012-09-06T12:15:28.483 回答
4

作为附加措施,您还可以阻止特定 IP。

http{
  deny 127.45.4.1;
  ...
}

或者将被阻止的 IP 放在单独的文件中

http{
  include blockedips.conf
  ...
}

阻止ips.conf

deny 1.12.4.5;
于 2015-03-04T10:39:41.563 回答
3

您还可以阻止特定国家/地区

http{
   geoip_country /usr/share/GeoIP/GeoIP.dat;
    map $geoip_country_code $allowed_country {
        default yes;
        FK no;
        FM no;
        EH no;
    }
}

GeoIP.dat 可以从http://dev.maxmind.com/geoip/geoip2/geolite2/下载 (我不隶属于 maxmind)

于 2015-03-04T10:52:20.643 回答