atom feed6 messages in ru.sysoev.nginxRe: error_page and log_not_found in n...
FromSent OnAttachments
Steffen WeberAug 11, 2008 1:20 am 
Igor SysoevAug 11, 2008 4:27 am.Other
Steffen WeberAug 11, 2008 8:05 am 
Steffen WeberAug 12, 2008 3:57 am 
mikeAug 12, 2008 9:44 am 
Igor SysoevAug 14, 2008 6:04 am.Other
Subject:Re: error_page and log_not_found in nginx 0.7.8
From:Igor Sysoev (is-G@public.gmane.org)
Date:Aug 11, 2008 4:27:37 am
List:ru.sysoev.nginx
Attachments:
patch.not_found - 0.9k

On Mon, Aug 11, 2008 at 10:20:36AM +0200, Steffen Weber wrote:

I think I'm either misunderstanding the purpose of the log_not_found directive or maybe there is a bug in nginx 0.7.8. In May 2008 Igor recommended [1] the following configuration snippet to hand off all requests for non-existing files to PHP:

location / { error_page 404 = /index.php; }

But this creates an entry in my error_log for each request that is handed off to PHP. Michael Shadle then pointed me to the log_not_found directive, but adding "log_not_found off;" to the configuration file does not seem to have any effect, no matter where I put it (http, server or location block).

The error I get originates from src/http/modules/ngx_http_index_module.c and reads

2008/08/11 10:04:17 [error] 5887#0: *1 "/doc/root/artikel/index.php" is not found (2: No such file or directory), client: 127.0.0.1, server: www.example.org, request: "GET /artikel/ HTTP/1.1", host: "www.example.org", referrer: "http://www.example.org/"

What am I doing wrong?

I could, of course, change the error_log directive to only log critical events, but I fear that I would miss some (more) important errors then.

The attached patch should fix the bug.

-- Igor Sysoev http://sysoev.ru/en/

Index: src/http/modules/ngx_http_index_module.c =================================================================== --- src/http/modules/ngx_http_index_module.c (revision 1479) +++ src/http/modules/ngx_http_index_module.c (working copy) @@ -332,6 +332,8 @@ static ngx_int_t ngx_http_index_error(ngx_http_request_t *r, u_char *file, ngx_err_t err) { + ngx_http_core_loc_conf_t *clcf; + if (err == NGX_EACCES) { ngx_log_error(NGX_LOG_ERR, r->connection->log, err, "\"%s\" is forbidden", file); @@ -339,9 +341,13 @@ return NGX_HTTP_FORBIDDEN; }

- ngx_log_error(NGX_LOG_ERR, r->connection->log, err, - "\"%s\" is not found", file); + clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);

+ if (clcf->log_not_found) { + ngx_log_error(NGX_LOG_ERR, r->connection->log, err, + "\"%s\" is not found", file); + } + return NGX_HTTP_NOT_FOUND; }