browse by category or date

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:

  1. debug
  2. info
  3. notice
  4. warn
  5. error
  6. crit
  7. alert
  8. 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 😀

GD Star Rating
loading...
Disable NGINX Error Logging For Specific HTTP Error Code, 3.0 out of 5 based on 1 rating

Possibly relevant:

About Hardono

Howdy! I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 11 years.

Incoming Search

can't-do-it, nginx

No Comment

Add Your Comment