5

I have apache2 and tomcat6(not installed from apt repository, manually downloaded and installed) running on port 80 with mod_jk setup. The jsp servlet pages are accessed pointing the browser to http://myapp.mydomain.com/ (virtual hosting is done in tomcat(server.xml) and in apache). I'm trying to redirect tomcat's error page 503 to custom error page when tomcat is down(pkill -9 java or /etc/init.d/tomcat stop) during deployment.

My apache's Document Root is /var/www/ so I place below entry in apache2.conf file

ErrorDocument 503 maintenance.html and created a file maintenance.html under /var/www. When I tested stopping the tomcat and I got the page redirected to maintenance.html without having the url changed but the actual page is not displayed, instead the file name maintenance.html is displayed on the browser. Could any one help me properly configuring apache that redirects to proper maintenance.html page when tomcat is down?.

user465465
  • 441
  • 3
  • 13
  • 26

2 Answers2

4

From the apache documentation,

URLs can begin with a slash (/) for local web-paths (relative to the 
DocumentRoot), or be a full URL which the client can resolve.

I guess ErrorDocument 503 /maintenance.html should work.

Raghuram
  • 51,854
  • 11
  • 110
  • 122
  • In the `/etc/apache2/sites-enabled/000-defaults` file the DocumentRoot is `/var/www/` instead `/var/www`. If I use `/maintenance.html` instead `maintenance.html` I'll get the same `Server Temporarly Unavailable` error page. – user465465 Jan 12 '11 at 10:44
  • 1
    Like http://server-ip/maintenance.html works and I can add `ErrorDocument 503 http://server-ip/maintenance.html` in the apache config file and this works but the page stays in the maintenance page and the user again have to point the url to http://myapp.mydomain.com/ after the tomcat is up. – user465465 Jan 12 '11 at 10:51
  • 1
    From apache docs (http://httpd.apache.org/docs/2.0/mod/core.html#documentroot), The DocumentRoot should be specified without a trailing slash. Good luck to you! – Raghuram Jan 12 '11 at 10:56
  • maintenance.html can contain a clickable link to your app or a periodic meta refresh to it. – Raghuram Jan 12 '11 at 10:59
  • It's just a normal html program and there is nothing like that as it is created by me. – user465465 Jan 12 '11 at 11:07
0

If you're using Apache with Tomcat connectors, the solution is slightly more complicated than simply adding and ErrorDocument directive. You have to explicitly tell Apache to NOT look within the mounted connector for your /maintenance.html file; rather it needs to look locally for it instead.

I posted my working solution to this problem here

Community
  • 1
  • 1
Andrij
  • 91
  • 1
  • 5