Custom error page for post queries

Maxim Dounin mdounin at mdounin.ru
Mon Aug 11 10:27:09 UTC 2014


Hello!

On Mon, Aug 11, 2014 at 03:39:40AM -0400, Keferoff wrote:

> Hi!
> 
> Current infrastructure:
> We have nginx/1.7.1 as frontend for java application. We have special
> requirement, when java app goes down we need response with 204 error code
> instead 500 or 502 and this works like in charm for GET queries but nit for
> POST. 
> 
> The question:
> How I need ti change my config for POST queries.

[...]

>   error_page 502 500 =204 @maintenance;
>   location @maintenance {
>     try_files $uri $uri/ /204/204.html =204;
>   }

The problem is that your config tries to use the /204/204.html 
file, and this will generate 405 error for POSTs, as static files 
doesn't suppport POSTs into them.

(Additionally, trying to use files here doesn't make sense, as 204 
responses doesn't return entities.)

Use something like:

    error_page 502 = /204;

    location = /204 {
        return 204;
    }

instead.

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



More information about the nginx mailing list