【问题标题】:How don't logging specif IP Address in Nginx?如何不在 Nginx 中记录特定的 IP 地址?
【发布时间】:2017-12-17 18:40:17
【问题描述】:

我正在获取我的 VPS 的 IP 数以千计的连接,如下所示:

51.15.76.184 - - [17 / Dec / 2017: 16: 31: 17 -0200] "CONNECT portal.geniptv.com:8080 HTTP / 1.1" 400 172 "-" "-

这些连接已被阻止(HTTP / 1.1 "400 = Bad request),但我在 /var/log/nginx 中的 access.log 文件大小增加了几 GB。

如何以及在哪里可以停止专门记录此 IP?

我有带有 ISPconfig 3 和 nginx 的 Debian 8

提前谢谢你。

【问题讨论】:

    标签: nginx debian ispconfig


    【解决方案1】:

    access_log 指令有一个选项,可以根据变量的值不记录请求。可以使用映射来设置该变量:

    map $remote_addr $logging {
        default 1;
        ~^51.15.76.184$ 0;
        # ... (if there are more, consider putting them in an included file)
    }
    
    server {
        access_log  /var/log/nginx/example.com.access.log main if=$logging;
        # ...
    }
    

    【讨论】:

    • 非常感谢科尔蒂尔尼。在您的帮助下,我能够阻止。我还禁止了 iptables iptables -A INPUT -s 51.15.76.184/32 -i eth0 -j DROP.
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-26
    • 1970-01-01
    • 1970-01-01
    • 2013-05-08
    • 2011-06-15
    • 2011-11-28
    • 2011-07-17
    相关资源
    最近更新 更多