nginx忽略favicon.ico日志

说明:
favicon.ico占用nginx error_log日志大量信息,把我们真正需要查看的日志给覆盖。因此这里,我们通过log_not_found off关闭它。


实现:
//把以下配置放到 server {} 块,关闭favicon.ico不存在时记录日志

location = /favicon.ico {
log_not_found off;
access_log off;
}
//log_not_found on|off,默认为on:启用或禁用404错误日志,这个指令可以用来禁止nginx记录找不到rebots.txt或favicon.ico这类文件的错误信息。

 
附录:
1. 网上有看到一句说:注意error_log off并不能关闭日志记录功能,它将日志文件写入一个文件名为off的文件中,如果你想关闭错误日志记录功能,应使用以下配置:error_log /dev/null crit;
off位置在/usr/local/nginx/off,即nginx的安装目录下

2. log_not_found off改成error_log off效果也一样,不同的是写成error_log off是将错误日志输出到off文件,而log_not_found则是关闭日志。

“nginx忽略favicon.ico日志”的2个回复

  1. access_log off;为关闭访问日志,比access_log /dev/null; 高效,nginx对 access_log 的off作了特殊处理http://nginx.org/en/docs/http/ngx_http_log_module.html
    error_log off;是错误的配置,必须使用error_log /dev/null;

    1. 嗯,access_log 确实是通过off来通过的。error_log off;这个我是真没看到,看官网http://nginx.org/en/docs/ngx_core_module.html#error_log,这边也确实没看到off关闭的。error_log file | stderr | syslog:server=address[,parameter=value] [debug | info | notice | warn | error | crit | alert | emerg];。应该也是通过error_log /dev/null;来关闭。
      谢谢

shang进行回复 取消回复

邮箱地址不会被公开。 必填项已用*标注