Forum: NGINX Custom error_page basic config problem.

Posted by Agus (Guest)
on 2013-01-14 23:03
(Received via mailing list)
Hi fellows,

I was having trouble creating a custom error_page. Here's the simple 
test
config i did:

server_name www.test1.com.ar;

error_log logs/www.test1.com.ar.http.error.log debug;
access_log logs/www.test1.com.ar.http.access.log main;

root /usr/local/www/www.test1;

    location / {
# Esto es para simular el geoip con un if.
if ( $remote_addr = "10.24.18.2" ) {
error_page 401 /custom/404b.html;
return 401;
}
    }


With that, i only got the nginx default error page. After turning on 
debug
i saw that when nginx goes to fetch the error_page mentioned it searches 
in
location / so it denies and send me the default error. Now i added a
location like this

    location = /custom/404b.html {
internal;
    }


Which made it work.

My question is is this is OK. If my solution is the correct one or 
perhaps
theres a better one. Also, this test is easy cause its local, but i want 
to
implemtn this in a proxy_pass situation. Probably the intercept_error..

Thanks for any hints you can give.
Posted by Agus (Guest)
on 2013-01-17 20:00
(Received via mailing list)
Weird. No one?

Cheers


2013/1/14 Agus <agus.262@gmail.com>
Posted by Maxim Dounin (Guest)
on 2013-01-21 04:15
(Received via mailing list)
Hello!

On Mon, Jan 14, 2013 at 07:02:41PM -0300, Agus wrote:

> root /usr/local/www/www.test1;
> With that, i only got the nginx default error page. After turning on debug
> i saw that when nginx goes to fetch the error_page mentioned it searches in
> location / so it denies and send me the default error.

This is expected behaviour - you return 401 once again during
error_page handling, and hence get builtin error.

> Now i added a location like this
>
>     location = /custom/404b.html {
> internal;
>     }
>
>
> Which made it work.

This is how it's usually handled - via separate location without a
check to deny access.

> My question is is this is OK. If my solution is the correct one or perhaps
> theres a better one. Also, this test is easy cause its local, but i want to
> implemtn this in a proxy_pass situation. Probably the intercept_error..
>
> Thanks for any hints you can give.

Separate location for handling errors is fine.


--
Maxim Dounin
http://nginx.com/support.html
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.