Apache reverse proxy error page when proxied server is down

I am using Apache2 as a reverse proxy for tomcat, my configuration being something like:

ProxyRequests Off

ProxyPass        / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/

My question is: can I configure Apache to show up a courtesy page (an "under construction" HTML static page) whenever Tomcat is down?


You can use the Apache ErrorDocument directive to do this. You should use a URL to point to your ErrorDocument otherwise if you use a filesystem reference you will get an additional 503 whilst trying to find it.

ErrorDocument 503 http://somehost.tld/errors/503.html

Here is solution without extra server or another port:

ProxyPass /http_errors/ !

#Actual proxy config, must be below exception!
ProxyPass / ajp://myserver:12345/

Alias /http_errors/ /var/www/http/
ErrorDocument 503 /http_errors/503.html

In short:

  1. Add proxy exception for some alias, like http_errors (must be placed before actual proxy rule)
  2. Map alias to real path (must be existing and accessible by Apache)
  3. Map given HTTP status code to certain file within alias

So for setup above, the file shown in case of problem is /var/www/http/503.html.


Apache will throw a 503 "Service unavailable" error when it can't connect to Tomcat. You could just create a "nice" 503 error page.

ErrorDocument 503 /var/www/html/error/gonefishing.html