Welcome! Log In Create A New Profile

Advanced

Custom error pages and access_log inheritance

October 02, 2015 07:30AM
Hi,

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. Please consider the following config:

------------------
server {
listen *:80;
server_name test.domain;
root /app/www/;

location / {}

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

access_log /app/log/test.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.

However if i add a custom error page for the 404 error on the server level:
------------------
server {
/* above config */

error_page 404 /x;

location = /x {
internal;
echo "error";
}
}
------------------
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:

------------------
server {
listen *:80;
server_name test.domain;
root /app/www/;

location / {}

location ~ \.html$ {
access_log /app/log/html.log custom;
error_page 404 /xhtml;
}

access_log /app/log/test.log custom;

error_page 404 /x;

location = /x {
internal;
echo "error";
}

location = /xhtml {
internal;
echo "error";
access_log /app/log/html.log custom;
}
}
------------------

Is there any way to have both 1) a custom error page and 2) all the access logs stay in the inital location's access_log, *without* having to define both error_page and the corresponding location with seperate log file?
Subject Author Posted

Custom error pages and access_log inheritance

bjoe2k4 October 02, 2015 07:30AM

Re: Custom error pages and access_log inheritance

Francis Daly October 02, 2015 08:38AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 92
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready