Welcome! Log In Create A New Profile

Advanced

Re: custom error pages for retun directive

Maxim Dounin
August 26, 2014 08:00AM
Hello!

On Tue, Aug 26, 2014 at 04:48:41AM -0400, kay wrote:

> It is not possible to set custom error page. For example
> /usr/share/nginx/404.html contains "test":
>
> server {
> error_page 404 /404.html;
>
> if ($request_method = "GET")
> return 404;
> }
>
> location / {
> proxy_pass http://localhost:8080;
> }
>
> location /404.html {
> /usr/share/nginx/404.html;
> }
> }

[...]

> Is it possible to get cutsom 404 error page with 404 error code using
> "return 404" directive?

The request processing with the above configuration is as follows:

- if (...) matches, 404 returned;

- error_page redirects the request to /404.html;

- if (...) again matches, 404 returned;

- recursive_error_pages is off, so builtin 404 page is returned.

As you can see, the problem is that "if (...)" specified at
server level matches again after the redirect. To fix things,
move the if into the "location /", it will prevent if from
matching requests to /404.html:

location / {
if ($request_method = "GET") {
return 404;
}

proxy_pass http://localhost:8080;
}

location = /404.html {
# static file
}

--
Maxim Dounin
http://nginx.org/

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

custom error pages for retun directive

kay August 26, 2014 04:48AM

Re: custom error pages for retun directive

Maxim Dounin August 26, 2014 08:00AM

Re: custom error pages for retun directive

kay August 26, 2014 08:41AM

Re: custom error pages for retun directive

Maxim Dounin August 26, 2014 09:54AM

Re: custom error pages for retun directive

kay August 26, 2014 11:01PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 80
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