0
条件付きアクセスログを使用してnginx/1.13.0を設定しようとしています。Nginx:複数の条件でログする
access_loggingのみ$ステータスコードに条件付きである場合は、すべてが正常に動作します:
http {
[..]
map $status $logworthy_status {
~^[4] 1;
default 0;
}
[..]
server {
[..]
access_log /var/log/nginx_access.log combined if=$logworthy_status;
[..]
}
}
デバッグログが期待通りにマップに動作を示しています。私は書き換えしようとした場合、
2017/06/13 11:34:14 [debug] 23153#0: *203 http map started
2017/06/13 11:34:14 [debug] 23153#0: *203 http script var: "401"
2017/06/13 11:34:14 [debug] 23153#0: *203 http map: "401" "1"
をしかし、 hereを示唆したように、これは複数の条件を可能にする:
http {
[..]
map $status $logworthy_status {
~^[4] 1;
default 0;
}
[..]
server {
[..]
set $logworthy 0;
if ($logworthy_status = 1) {
set $logworthy 1;
}
access_log /var/log/nginx_access.log combined if=$logworthy;
[..]
}
}
ログメッセージは生成されません。デバッグログを確認すると、$ statusのマッピングさえもうまくいきません。
2017/06/13 11:38:12 [debug] 23631#0: *204 rewrite phase: 0
2017/06/13 11:38:12 [debug] 23631#0: *204 http script value: "0"
2017/06/13 11:38:12 [debug] 23631#0: *204 http script set $logworthy
2017/06/13 11:38:12 [debug] 23631#0: *204 http script var
2017/06/13 11:38:12 [debug] 23631#0: *204 http map started
2017/06/13 11:38:12 [debug] 23631#0: *204 http script var: "000"
2017/06/13 11:38:12 [debug] 23631#0: *204 http map: "000" "0"
2017/06/13 11:38:12 [debug] 23631#0: *204 http script var: "0"
2017/06/13 11:38:12 [debug] 23631#0: *204 http script value: "1"
2017/06/13 11:38:12 [debug] 23631#0: *204 http script equal
2017/06/13 11:38:12 [debug] 23631#0: *204 http script equal: no
2017/06/13 11:38:12 [debug] 23631#0: *204 http script if
2017/06/13 11:38:12 [debug] 23631#0: *204 http script if: false
誰かがこれを説明できますか?要求は期待通りに処理され、nginxは401を返しますが、これはログに記録されません。