Custom error pages and access_log inheritance

Francis Daly francis at daoine.org
Fri Oct 2 12:36:26 UTC 2015


On Fri, Oct 02, 2015 at 07:30:28AM -0400, bjoe2k4 wrote:

Hi there,

> i was wondering if it is possible to have custom error pages *without* the
> error page locations inheriting the http or server level access_log
> directives.

Requests are logged in the context of a location where processing ends.

So if your custom error page is handled in the same location that the
initial request is handled in, you'll use the same access_log.

>     location ~ \.html$ {
>         access_log /app/log/html.log custom;
>     }

> All access logs for requests "/exists.html" with status code 200 and
> "/nonexists.html" with status code 404 are in the html.log file.

The two requests are handled in the same location, and there are no
internal redirects to a different location.

> The access logs for "/nonexists.html" are now located in the file
> "test.log", which makes perfect sense, since the server level access_log
> directive is inherited by location /x. The only way to fix this is a
> somewhat lengthy config like this:

"error_page 404 /404.html;" ?

> 2) all the access logs stay in the inital location's access_log,

That's not what nginx does.

http://nginx.org/en/docs/http/ngx_http_log_module.html

I think that you would have to come up with one error_page per "normal"
location, then create a new location for each error_page, that had the
same access_log configuration as the location it came from.

Or have the error_page value be handled in the same location that it is
configured in.

Good luck with it,

	f
-- 
Francis Daly        francis at daoine.org



More information about the nginx mailing list