I'm using tomcat6 with mod_jk setup(both running at port 80) on ubuntu9.10 and 8.10 servers. I deploy war files under /usr/share/tomcat/webapps. During deployment, as I restart the tomcat, I will get the following page when the tomcat application is accessed on the browser:
Service Temporarily Unavailable
The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.
Apache/2.2.11 (Ubuntu) mod_jk/1.2.15 Server at 192.168.2.54 Port 80
How could I redirect this page to some other self created maintenance page while the tomcat server is down?.
A common requirement is to have Apache display a custom maintenance error page when Tomcat is down or when an application running in Tomcat is down. This is quite easy to do. All we need to do is add an ErrorDocument entry to our http. conf file.
Try putting App_Offline. htm to the root directory. Save this answer.
html file what you want the maintenance page to show. To enable maintenance mode in this case you would just touch /var/www/maintenance/ALL or touch /var/www/maintenance/example.com .
If you're using mod_jk and tomcat connectors this is expected behavior. If you use something like
ErrorDocument 503 "foo"
you will see 'foo' rendered on the page or
ErrorDocument 503 "http://www.somedomain.com"
which will direct you to somedomain.com successfully. But if you use something like
ErrorDocument 503 /maintenance.html
Apache won't be able to find [DocumentRoot]/maintenance.html since it's looking within the context of the tomcat connector. You need to unmount your connector and tell Apache to serve static content from another location.
This is a good guide to get you started with mod_jk. Custom Error Pages with Apache and Tomcat Connectors
edit: Here's the solution I employed to get our custom 503 pages to render properly.
First, all of our custom error pages are prefixed with the error code since it's likely our web app won't contain files with these status codes as the root of the file name. So for using your example, I would have something like the following three files in a directory called 'custom_errors':
/503_maintenance.html
/503_maintenance.css
/503_corp_logo.png
This makes it easy to exclude any files related to custom error pages from the jk mount. In our vhost file, then we set the error document location and alias
#Alias the location of your custom error page files
Alias /error/ /var/apache2/2.2/htdocs/custom_errors
ErrorDocument 503 /error/503_maintenance.html
#mount the core tomcat application
JkMount /* myWorker
#set the 503 code if myWorker is unavailable
#and exclude the 503 pages from the tomcat/jboss application
JkMount /* myWorker;use_server_errors=503
JkUnMount /503* myWorker
This basically tells Apache and mod_jk not to mount any files with the 503 prefix under the context of the tomcat connector and will look locally for those files instead. If you don't want to use a location relative to DocumentRoot, you can use and Alias like I did.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With