Nginx error handling/error page

Hi,

This is a newbie question and was probably asked before.

I have an Apache web server, and nginx is used as reverse proxy server.
In
nginx, I need to parse the response from Apache, if the error code from
Apache is 500, 502, 503, 504, or if the response body from Apache is
empty,
I will do some special processing before send the static error page to
the
client.

The conf has entry like this:

error_page 500 502 503 504 /50x.html;

What’s the best way to do this?