Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

404 error doesn't appear in Apache error.log

Tags:

logging

apache

If a visitor gets 404 error, nothing is written in apache error.log. In access log it appears like this:

GET /qqq HTTP/1.1" 404 409 "-"

And nothing in error.log. I have tried everything about LogLevel. As I understand, it is because that 404 page is custom page like

ErrorDocument 404 /new404.html

But I run search through all /etc/apache2 for text "404" in files and nothing was found there (instead of commented lines). What can be the problem? Or maybe I can somehow disable custom 404 page in .htaccess file? Or any other ways to display 404 errors in error.log?

like image 250
Vasya Avatar asked Apr 12 '16 08:04

Vasya


2 Answers

As the person who filed the Apache bug which demoted 404 from Error to Info level as of Apache 2.4.1, here's the justification:

In production HTTP servers open to the Internet, 404s happen all the time. Malware, scanner scripts, and all sorts of other things probe Web servers for vulnerabilities or just because they can, and these things would all trigger errors which will end up being logged somewhere if the appropriate error level is set.

Most production Web server admins are content with seeing 404s in their access logs (which are logged right alongside 200s and 30x redirects), and want to see real server problems -- things they have control over fixing -- in the error log. The logging of 404s in error.log can, in some servers, be so much log spam that it drowns out legitimate problems needing the administrator's attention.

404 is a content issue, not a server issue. So my recommendation is to look in your access.log (or equivalent) for them. If you really want content related issues logged in error.log, you need to set LogLevel core:info. This will give you 404s there, and a few other kinds of content-related error messages too.

like image 185
Todd Vierling Avatar answered Nov 04 '22 10:11

Todd Vierling


404 "errors" don't normally appear in the Apache error log, regardless of whether you have a custom ErrorDocument defined or not.

A 404 error is not strictly a server error. It's an expected HTTP response, so it naturally appears in the access log (as you have stated), not in the error log. The "404" is the HTTP response code, not a server error code.

However, you should be able to enable additional "information" messages in your error logging (eg. LogLevel info on Apache 2.4) to get this "information" in your system error log:

[Mon Feb 06 08:00:00.090525 2017] [core:info] [pid 13876:tid 1748] [client 203.0.113.111:54493] AH00128: File does not exist: /home/user/public_html/path/to/file

Note, however, that there is no mention of "404" - which maybe why your searches came up blank. This LogLevel should not be maintained on a production server.

like image 45
MrWhite Avatar answered Nov 04 '22 09:11

MrWhite