This blog log file grows quite fast. One main reason that I notice is that there are many malicious actors who are probing WordPress blogs to find a certain exploits. By checking a certain file, they can assume that the blog has some kind of vulnerabilities. As shown below, these are requests for files which are not exists in my server. Normal blog readers will not requests for these files.
Since I’ve grown tired of cleaning the log files from these “file not found” error messages, I decided to disable NGINX’s logging, specifically for 404 (resource not found) error message. Based on this article, here’s how to do it:
map $status $loggable { ~^[23] 0; default 1; } access_log /path/to/access.log combined if=$loggable;
So we just need to modify it for error_log and to handle 404 error:
map $status $loggable { ~^404 0; default 1; } error_log /path/to/access.log combined if=$loggable;
WARNING
Above code won’t work. This is what happen if we don’t RTFM. It turns out the if is specific to access_log
Syntax: access_log path [format [buffer=size] [gzip[=level]] [flush=time] [if=condition]];
access_log off;
Default:
access_log logs/access.log combined;
Context: http, server, location, if in location, limit_except
where as for error_log:
Syntax: error_log file [level];
Default:
error_log logs/error.log error;
Context: main, http, mail, stream, server, location
It means we can only limit the logging, by specifying the lowest log level. Anything below that level will not be logged. These are the levels starting from the lowest:
- debug
- info
- notice
- warn
- error
- crit
- alert
- emerg
So if we choose error level, debug to warn will not be logged.
Anyway, I hope it helps. I’m sorry for the misleading title 😀
loading...
About Hardono
Incoming Search
can't-do-it, nginx