问题:nginx: [emerg] 未知的日志格式

我试图排除 pingdom 出现在我的 nginx 访问日志中,但是出现错误:

nginx: [emerg] unknown log format "if=$excluded_ua" in /etc/nginx/nginx.conf:55
nginx: configuration file /etc/nginx/nginx.conf test failed

在我添加的配置中:

http {
...

  map $http_user_agent $excluded_ua {
         pingdom  0;
         ~Preload 0;
         default 1;
     }

        access_log /var/log/nginx/access.log combined if=$excluded_ua;

...
}

纠正错误后,我仍然在我的访问文件中看到 Pingdom 条目。

94.247.174.83 - - [26/Oct/2017:22:02:56 +0100] "GET / HTTP/1.1" 200 14832 "-" "Pingdom.com_bot_version_1.4_(http://www.pingdom.com/)"

解答

您可能需要包含一个 log_format。默认是“组合”。可以试试access_log /var/log/nginx/access.log combined if=$excluded_ua;吗?

http://nginx.org/en/docs/http/ngx_http_log_module.html#access_log

Logo

开发云社区提供前沿行业资讯和优质的学习知识,同时提供优质稳定、价格优惠的云主机、数据库、网络、云储存等云服务产品

更多推荐