views:

386

answers:

1

I have a single Tomcat 6 instance that frequently needs to be rebooted because of PermGen issues after multiple WAR deployments.

In a Production environment it's clearly bad practice to take down the site, leaving any visitors with nothing but a connection failure. The big picture is to set up a fail-over Tomcat cluster of one or two more instances, but for now I'd like a simple solution:

When Tomcat is down, all requests are forwarded to an Apache HTTP server running 1 simple "Site is under maintenance" type page.

I assume I need some small, super fast proxy to sit in front of Tomcat, feeding it requests and monitoring its health. If it dies, it simply sends those requests to Apache HTTP.

Ideas?

+2  A: 

You could just generally use Apache in front of your tomcat install. Set up a redirect proxying rule to your tomcat. If that doesn't work, apache will send a "503 Service Temporarily Unavailable" which you could configure to be your maintenance page.

The apache application file would look somewhat like this

<VirtualHost *>
    ServerName example.com
    ServerAlias *.example.com
    ServerAdmin [email protected]

    RewriteEngine on
    RewriteRule ^/static/(.*) /some/path/for/static/files/static/$1 [L]
    RewriteRule ^(.*) http://127.0.0.1:8080$1 [P]

    ErrorLog /var/log/apache2/example/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog /var/log/apache2/example/access.log combined
    ServerSignature On

    ErrorDocument 503 /static/site_down.html
</VirtualHost>

The first rewrite rule changes all files in below a certain URI ( /static/ ) to a directory from which those static files are served directly without proxying. You could use this to serve all static resources from your website, too, which would somewhat make up for the general (small) performance loss of having an apache in front of your tomcat.

The ErrorDocument directive changes the normal 503 response to the document site_down.html lying in this static path.

For this to work you need to enable mod_rewrite and mod_proxy/mod_proxy_http and enable the proxy in your apache2 config

<Proxy *>
        Order Deny,Allow
        Deny from all
        Allow from all
</Proxy>
fforw