# How to avoid 404 for images in access log?

**URL:** <https://www.ruby-forum.com/t/how-to-avoid-404-for-images-in-access-log/212123>\
**Category:** NGINX\
**Created:** [September 22, 2011, 5:40pm UTC](https://www.ruby-forum.com/t/how-to-avoid-404-for-images-in-access-log/212123 "2011-09-22T17:40:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [September 22, 2011, 5:40pm UTC](https://www.ruby-forum.com/t/how-to-avoid-404-for-images-in-access-log/212123/1 "2011-09-22T17:40:17Z")

</div>

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](http://mydomain.com.page.html) …

Posted at Nginx Forum:

> **[How to avoid 404 for images in access log?](https://forum.nginx.org/read.php?2,215626,215626#msg-215626)**
>
> 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 ...

---

<div class="post-metadata">

**Author:** ![etrader](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b5e925/32.png) [@etrader](https://www.ruby-forum.com/u/etrader)\
**Post date:** [September 22, 2011, 5:45pm UTC](https://www.ruby-forum.com/t/how-to-avoid-404-for-images-in-access-log/212123/2 "2011-09-22T17:45:51Z")

</div>

On 9/22/11, etrader [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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](http://mydomain.com.page.html) …

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

---

<div class="post-metadata">

**Author:** ![etrader](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b5e925/32.png) [@etrader](https://www.ruby-forum.com/u/etrader)\
**Post date:** [September 22, 2011, 5:53pm UTC](https://www.ruby-forum.com/t/how-to-avoid-404-for-images-in-access-log/212123/3 "2011-09-22T17:53:53Z")

</div>

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:

> **[Re: How to avoid 404 for images in access log?](https://forum.nginx.org/read.php?2,215626,215630#msg-215630)**
>
> 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 ...

---

<div class="post-metadata">

**Author:** ![etrader](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b5e925/32.png) [@etrader](https://www.ruby-forum.com/u/etrader)\
**Post date:** [September 22, 2011, 6:17pm UTC](https://www.ruby-forum.com/t/how-to-avoid-404-for-images-in-access-log/212123/4 "2011-09-22T18:17:24Z")

</div>

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:

> **[Re: How to avoid 404 for images in access log?](https://forum.nginx.org/read.php?2,215626,215634#msg-215634)**
>
> 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 ...

---

<div class="post-metadata">

**Author:** ![etrader](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b5e925/32.png) [@etrader](https://www.ruby-forum.com/u/etrader)\
**Post date:** [September 22, 2011, 6:03pm UTC](https://www.ruby-forum.com/t/how-to-avoid-404-for-images-in-access-log/212123/5 "2011-09-22T18:03:48Z")

</div>

On 9/22/11, etrader [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.

---

<div class="post-metadata">

**Author:** ![etrader](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b5e925/32.png) [@etrader](https://www.ruby-forum.com/u/etrader)\
**Post date:** [September 22, 2011, 6:16pm UTC](https://www.ruby-forum.com/t/how-to-avoid-404-for-images-in-access-log/212123/6 "2011-09-22T18:16:47Z")

</div>

> 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](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

---

<div class="post-metadata">

**Author:** ![etrader](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b5e925/32.png) [@etrader](https://www.ruby-forum.com/u/etrader)\
**Post date:** [September 22, 2011, 6:54pm UTC](https://www.ruby-forum.com/t/how-to-avoid-404-for-images-in-access-log/212123/7 "2011-09-22T18:54:36Z")

</div>

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:

> **[Re: How to avoid 404 for images in access log?](https://forum.nginx.org/read.php?2,215626,215642#msg-215642)**
>
> 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 ...
