I have two use cases:
HTTPD is a proxy for a Tomcat application
HTTPD is a proxy for a PHP application
For compliance and security needs all 50x errors must be rewritten to 503 prior to sending back to a client. Exposing 50x errors leaks information about your application, so is bad practice.
I still wish to see 500s in the HTTPD log files, but must rewrite the HTTP error sent back to clients.
Constraints:
Using an external program or other application is out of the question, i.e. varnish, pound, nginx et al.
I do not wish to send back an error page, I only need to rewrite the HTTP status. i.e. change the
HTTP/1.1 500
to a503
in the following:[user@host]$ curl -I http://localhost:8080/500.php HTTP/1.1 500 Internal Server Error <OUTPUT OMITTED>
Is this possible?
Note: I created error pages with:
for http_status in 401 403 500 501 503; do
echo -e "<?php\nhttp_response_code(${http_status});" > ${http_status}.php
done
Eureka!!
After cobbling together several other *exchange posts I have a workable solution; specify an error document for a backend 500 then return 503 for all calls to that document.
This block of code can sit in a
VirtualHost
definition:Sources:
Bonus Puppet Points: