Nginx replace error 500 with error 503

500-errornginx

I have nginx proxy with backend.

Sometimes the backend return HTTP 500.
In this cases, I want nginx to change the error code from 500 to 503.

Is this possible?

Note: I do not mind to replace "global" 500 error to 503.

Best Answer

The answer to this SO question gives a couple of options, the simplest of which seems to be:

Furthermore, it is possible to change the code of answer to another, for example: error_page 404 =200 /.empty.gif;

Or, in your case:

error_page 500 503 5xx_error.html

Or something like it.

The docs for error_page directive can be found here.