7

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?

13

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
|improve this answer|||||
  • 1
    That is correct, since I am proxying all the pages starting from "/", so there won't be any web server actually servicing an error page of the type "/var/www/html/error/gonefishing.html" – Overflow May 13 '11 at 11:29
  • There is option to do that without extra URL. Use alias. See my answer below. – Jaroslav Kuboš Jan 21 '19 at 10:06
2

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.

|improve this answer|||||
1

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
|improve this answer|||||
0

If your local server has apache listening on default ports you could point a ERROR uri to local host and have custom error pages available there. Will negate need for separate domain / server

ProxyPass /ERROR http:// localhost:80/

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

ErrorDocument 503 /ERROR/custom_50x.html
|improve this answer|||||
0

You could also prevent all /error/ requests from being proxied to the backend server:

ProxyPass /error/ !

ProxyPass        / http:// localhost:8080/
ProxyPassReverse / http:// localhost:8080/
|improve this answer|||||
-1

The order of ProxyPass statements as listed in @snyman's info is very important.. proxypass error should be the first proxypass statement for the virtualhost before any other proxypass statements are written..

this is my experience on centos 7 with apache 2.4 and tomcat7

|improve this answer|||||
  • This does not answer the question. If it is actually the case for Centos 7 and the comment of snyman's answer then you should consider adding a comment to his answer. – reichhart Aug 25 '18 at 8:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.