我需要从访问日志中排除所有具有指定地址的记录,为此我写道:
map $remote_addr $no_log_by_ip {
"xx.xx.xx.xx" 0;
default 1;
}
access_log /path_to_log/access.log combined if=$no_log_by_ip;
还需要从访问日志中排除所有代码为 403 的记录,我写道:
map $status $no_log_by_status {
403 0;
default 1;
}
access_log /path_to_log/access.log combined if=$no_log_by_status;
它是单独工作的。我们如何才能使这两种条件同时发挥作用,即这样日志中就没有指定 IP 的条目和来自任何 IP 的 403 条目了吗?
尝试过:
access_log /path_to_log/access.log combined if=$no_log_by_status if=$no_log_by_ip;
但只有最后一个 if 有效,即在这种情况下,if=$no_log_by_ip。
要检查 IP,最好使用地理模块。
if=..
不能在 中使用twoaccess_log
,但可以map
在 中使用变量。结果将会像这样:
UPD:您可以在单独的日志中写入 403。为此,您需要添加另一个
access_log
具有您自己的条件的指令: