Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Have nginx return a 204 instead of 5xx

Tags:

nginx

I need my nginx front-end to return 204 when the back-end reply a 5xx or timeout.

Is it possible?

Thanks

like image 294
François-Xavier Gsell Avatar asked Mar 17 '16 06:03

François-Xavier Gsell


2 Answers

Okay, finally I used:

location @return_204 {
    return  204;
}

location / {
        proxy_pass http://zzz;
        proxy_intercept_errors on;
        error_page 500 502 503 504 = @return_204;

}
like image 176
François-Xavier Gsell Avatar answered Nov 19 '22 17:11

François-Xavier Gsell


You can use the error_page directive to achieve this. Not that you would also need to set proxy_intercept_errors to make Nginx process the errors.

location / {
    ...
    proxy_intercept_errors on;
    error_page 500 502 503 504 =204;
    ...
}
like image 2
Lochnair Avatar answered Nov 19 '22 16:11

Lochnair