我有一个centos 7服务器nginx 1.6.2,我想停止错误日志,当一个search引擎的僵尸程序在我的网站发生404错误。 这是为了有一个干净的错误日志,只有“真正的错误”。
这怎么可能 ?
我已经在我的虚拟主机中试过了,但是不起作用
server { ... error_log /var/log/nginx/errors.log; if ($http_user_agent ~* (googlebot|yahoo|bingbot)) { error_log /dev/null crit; } ... }
作为回报,nginx服务重启失败:
nginx:[emerg]“error_log”指令在/etc/nginx/conf.d/mysite.conf中不允许:18
一个主意 ? 先谢谢你 !
如nginx文档中所述 ,方向error_log不能在内部if 。
语法 :error_log file | stderr | syslog:server = address [,parameter = value] [debug | 信息| 通知| 警告| 错误| 暴击| 警报| EMERG];
默认值 :error_log logs / error.log错误;
上下文 :主,http,服务器,位置
为了过滤error_log条目,你不能只依靠nginx。 一些想法是使用syslog来过滤日志行。 Nginx 1.7.1及以上版本支持sysloglogging(当然你必须更新nginx版本)。
每个系统日志软件都有不同的过滤语法。 例如:
当然,你可以使用grep -v从你的日志中手动过滤机器人:)。
最后我find了一个中间解决scheme:
server { ... error_log /var/log/nginx/errors.log; location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ { try_files $uri =410; access_log off; log_not_found off; } }
这段代码避免了没有关键文件的错误logging。
感谢您的帮助