丢弃不需要的连接

D_G*_*y13 17 bots nginx

我想阻止不需要的Bots访问服务器上的站点.

当检测到某个Bot时,nginx能否立即丢弃/终止连接?

if ($http_user_agent ~ (agent1|agent2) ) {
    **KILL CONNECTION**;
}
Run Code Online (Sandbox Code Playgroud)

像上面的例子.

小智 33

使用return 444; 这个非标准状态代码444会导致nginx只是关闭连接而不响应它.

if ($http_user_agent ~ (agent1|agent2) ) {
    return 444;
}
Run Code Online (Sandbox Code Playgroud)

  • nginx [关于444的文档](http://nginx.org/en/docs/http/request_processing.html#how_to_prevent_undefined_server_names) (2认同)