Using the access_log if directive in 1.6.x

Hi,

I’m using nginx 1.6.2 on Amazon ec2 linux server. The problem I’m having
is
that all my 404 errors are going to my access.log. I want them to be
redirected to error.log instead.

I saw on other forums that with nginx 1.7+, I can use the if directive
of
access_log to do something like:

map $status $errorable {
   ~([^23][0-9][0-9]) 1;
   default 0;

}

access_log /media/ephemeral0/log/nginx/error.log combined
if=$errorable;

However, I’m not able to do the same with 1.6.2. I don’t think I can
update
to 1.7+ as it is not available for ec2 linux servers yet. Is there an
alternative for doing the same with 1.6.2?

Thanks.

Posted at Nginx Forum:

On Thursday 11 December 2014 00:33:24 sudharshanr wrote:

   ~([^23][0-9][0-9]) 1;

You can specify separate location for the 404 error page:

error_page 404 /404.html;

location /404.html {
access_log /media/ephemeral0/log/nginx/error.log combined;
}

Or use our official AMIs:

wbr, Valentin V. Bartenev

Valentin V. Bartenev Wrote:

access_log to do something like:
update

nginx mailing list
[email protected]
nginx Info Page

Hello Valentin,

Thank you for your reply. Just one question. It is not just the 404
errors
that I want to redirect. I want to redirect all 4xx and 5xx errors. I
have
updated my config file as below, but it doesn’t seem to work. The 404
errors
still go to access.log

server {


root /wdrive/www;

access_log /mnt/log/nginx/access.log ;
error_log /mnt/log/nginx/error.log;

error_page 400 401 402 403 404 /error4x.html;
error_page 500 501 502 503 /error5x.html;

location /error4x.html{
    access_log /mnt/log/nginx/error.log;
}

location /error5x.html{
    access_log /mnt/log/nginx/error.log;
}

location / {
    ....
}

}

I have created error4x.html page in /wdrive/www.

Thanks.

Posted at Nginx Forum:

On Thursday 11 December 2014 13:25:45 sudharshanr wrote:
[…]

...
}

I have created error4x.html page in /wdrive/www.

Thanks.

By default, the errors generated by nginx itself are only handled
by the error_page directive. If you want to intercept errors from
upstream as well then you need to turn on proxy_intercept_errors.

See the docs: Module ngx_http_proxy_module

It’s always a good idea to provide your full configuration with
a question.

wbr, Valentin V. Bartenev