502 “Error reading from remote server” when upstream service errors

502-errorapache-2.4reverse-proxy

I have apache set up as a reverse proxy.
When the upstream service has an error (e.g. 500) the error is not returned to the client, but instead apache serves up a 502 "Error reading from remote server".

I would like the original error to be returned to the client.

N.B. when the upstream service works correctly (200 OK) then apache returns the response as expected. 500 Responses are masked.

Calling the upstream service directly returns the correct 500 response and content without issue.

This is what we have now:

ProxyPass "/path" "http://host:port/path"
ProxyPassReverse "/path" "http://host:port/path"

And the response when the service returns 500

Bad Gateway!
The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request GET /path/to/resource.
Reason: Error reading from remote server
If you think this is a server error, please contact the webmaster.
Error 502
publichostname
Apache/2.4.6 (Linux/SUSE) 

Is there some apache config change that will enable apache to forward the original response, regardless of the status code?

Best Answer

You need to install at least 2.4.16.

This behaviour was a bug in the version you are using, fixed in 2.4.13 (not released)

*) mod_proxy: Don't put the worker in error state for 500 or 503 errors returned by the backend unless failonstatus is configured to. PR 56925. [Yann Ylavic]