# Redirect 404 errors to a separate log file

**URL:** <https://www.ruby-forum.com/t/redirect-404-errors-to-a-separate-log-file/222405>\
**Category:** NGINX\
**Created:** [August 27, 2012, 2:02pm UTC](https://www.ruby-forum.com/t/redirect-404-errors-to-a-separate-log-file/222405 "2012-08-27T14:02:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [August 27, 2012, 2:02pm UTC](https://www.ruby-forum.com/t/redirect-404-errors-to-a-separate-log-file/222405/1 "2012-08-27T14:02:03Z")

</div>

I have been trying for a whole day to figure out how to redirect 404  
errors  
to a separate log file. I managed to do this in the server directive:

error\_page 404 = @404;  
location @404 {  
error\_log /var/log/nginx/404.log;  
}

This does write all 404 errors to 404.log, but the problem is that it  
also  
writes these errors in the default error.log, and I don’t want that. I  
want  
404 errors to be writtent to only into the 404.log.

Do you have an idea how to do this?

Posted at Nginx Forum:

> **[Redirect 404 errors to a separate log file](https://forum.nginx.org/read.php?2,230087,230087#msg-230087)**
>
> I have been trying for a whole day to figure out how to redirect 404 errors to a separate log file. I managed to do this in the server directive: error\_page 404 = @404; location @404 { error\_log /var/log/nginx/404.log; } This does write al

---

<div class="post-metadata">

**Author:** ![kustodian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/b782af/32.png) [@kustodian](https://www.ruby-forum.com/u/kustodian)\
**Post date:** [September 3, 2012, 10:49am UTC](https://www.ruby-forum.com/t/redirect-404-errors-to-a-separate-log-file/222405/2 "2012-09-03T10:49:12Z")

</div>

Hello!

On Fri, Aug 24, 2012 at 04:31:17AM -0400, kustodian wrote:

> 404 errors to be writtent to only into the 404.log.
> 
> Do you have an idea how to do this?

Errors to error\_log are logged once they happen, so you can’t  
configure separate error\_log to log specific errors (in contrast  
to access\_log).

However you may control whether to log “not found” errors or not -  
there is configuration directive “log\_not\_found” for this, see  
[Module ngx\_http\_core\_module](http://nginx.org/r/log_not_found).

Maxim D.
