How to avoid 404 for images in access log?

My access log is full of 404 logs for images not found; thus, it is
difficult to find real 200 successful visits. The lines include

… GET /css/img/calendar.png HTTP/1.1" 404 31
"http://mydomain.com.page.html

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,215626,215626#msg-215626

On 9/22/11, etrader [email protected] wrote:

My access log is full of 404 logs for images not found; thus, it is
difficult to find real 200 successful visits. The lines include

… GET /css/img/calendar.png HTTP/1.1" 404 31
"http://mydomain.com.page.html

Try something like
cat access.log | grep " 200 "

You mean to read only 200 requests in ssh or something like that?
I am looking for a way to avoid writing 404 requests in access log file
to keep the file tidy.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,215626,215630#msg-215630

Isn’t it possible to use multiple access_log to split the access log to
traffic and 404 logs ? Or probably writing 404 logs to error_log.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,215626,215634#msg-215634

On 9/22/11, etrader removed_email_a[email protected] wrote:

You mean to read only 200 requests in ssh or something like that?
I am looking for a way to avoid writing 404 requests in access log file
to keep the file tidy.

There is a way. But 404 requests are essential for security, i.e. to
see when someone is trying to hack your website, etc.

My access log is full of 404 logs for images not found; thus, it is difficult to
find real 200 successful visits. The lines
include
… GET /css/img/calendar.png HTTP/1.1" 404 31
"http://mydomain.com.page.html

Depending on if you don’t want to log 404 requests at all or just for
the images can probably do something like this:

location ~* ^.+.(jpg|jpeg|gif|png)$ {
error_page 404 @nolog;
}

location @nolog {
access_log off;
}

If you want it for any request just use the error_page without location
or even give a different logfile for the 404s.

rr

Thanks Reinis! It worked like a charm. But I have another problem (maybe
I should to start a new thread). It lists the access of my own server to
images. When someone visits an html page, an addition to this trick, a
line is added with my server IP for reading the image within the html
page. Since I just want the track of my traffic, this is useless to have
it as my server has loaded the images.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,215626,215642#msg-215642

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs