大网数据广告活动
服务器运维问答

Convert apache config to nginx equivalent for logs

· 52CE 我爱测

I have this custom log in apache SetEnvIFNoCase User-agent "ELB-HealthChecker/2.0" skiplog LogFormat "%t \"%r\" %>s %O | client:%a | Local:%A | Host:%v | %H | %m | %P(pid) | TimeTaken:%T | %q |DataReceived:%I-Sent:%O-Total:%S | %…

问题原文

原帖链接 · Master · CC BY-SA 4.0

I have this custom log in apache

 SetEnvIFNoCase User-agent "ELB-HealthChecker/2.0" skiplog
 LogFormat "%t \"%r\" %>s %O | client:%a | Local:%A | Host:%v | %H | %m | %P(pid) | TimeTaken:%T | %q |DataReceived:%I-Sent:%O-Total:%S | %l | %u | \"%{Referer}i\" \"%{User-Agent}i\"" mylog
 LogFormat "%a %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined_mylog
 CustomLog /var/log/apache2/access.log mylog env=!skiplog
 CustomLog /var/log/apache2/access_org.log combined_mylog env=!skiplog

Basically i want to skip the log if user agent is "ELB-HealthChecker/2.0"

Now i have shifted to nginx and i am not sure how to use it in there

已采纳解答

原帖链接 · Michael Hampton · CC BY-SA 4.0

The nginx access_log directive accepts a parameter if which causes it to log only if the given condition is not false or an empty string.

So, you can set a variable and in the case that that user agent appears set the variable to 0. You can do this most easily in a map:

map $http_user_agent $loggable {
    default                 1;
    ELB-HealthChecker/2.0   0;
}

Then you can modify access_log to check the variable:

    access_log /var/log/nginx/whatever-access.log log_format_name if=$loggable;

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-10-30)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。