nginx.conf-http块:
map $status $loggable {
~^[23] 0;
default 1;
}
有人可以告诉我为什么这对我不起作用吗? 即使状态码是200或301,我也总是得到默认值1。
例如,以下地图可以正常工作:
map $remote_addr $islocal {
"127.0.0.1" 0;
"192.168.178.100" 0;
default 1;
}
该日志文件显示$ status提供了正确的状态代码。
nginx.conf-http块:
log_format main '$loggable $status - [$time_local] - $remote_addr - "$request"';
webpage.conf-服务器块:
access_log /share/NGinX/var/log/access.log main if=$loggable;
日志文件:
1 200 - [20/Jan/2019:12:49:38 +0100] - ...
1 301 - [20/Jan/2019:13:04:43 +0100] - ...
1 500 - [20/Jan/2019:13:11:44 +0100] - ...
1 301 - [20/Jan/2019:13:48:05 +0100] - ...
1 500 - [20/Jan/2019:13:48:06 +0100] - ...
1 200 - [20/Jan/2019:13:59:55 +0100] - ...
1 200 - [20/Jan/2019:13:59:58 +0100] - ...
1 404 - [20/Jan/2019:14:28:03 +0100] - ...