9

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?

6 Answers 6

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
2
  • 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, 2011 at 11:29
  • 1
    There is option to do that without extra URL. Use alias. See my answer below. Jan 21, 2019 at 10:06
8

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.

2

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
1
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
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/
-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

1
  • 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, 2018 at 8:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .