Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am running a JBoss web app (AS 6 Final) hosted on linux (Debian). I would like to implement a failover solution so that when JBoss is down, a static web page is served in its place.

My current solution is to run Apache as a reverse proxy (described here), which allows me to serve .php files from apache and forward all other requests to JBoss. But I am not sure how make Apache step in when JBoss is down?

Note. both apache and jboss will be running on the same box, this is (Application failover rather then server failover) to cover times when JBoss is re-deploying etc. So I am looking for the simplest solution really

Many thanks

share|improve this question

3 Answers 3

up vote 0 down vote accepted
+100

If you want just a simple static page for failover, then use custom error message for your apache virtual host.

<VirtualHost *:80>
ServerName www.yourdomain.tld
ServerAlias yourdomain.tld

#Most Common errors for proxy
ErrorDocument 500 /demoWeb/errorpage.php 
ErrorDocument 502 /demoWeb/errorpage.php 
ErrorDocument 503 /demoWeb/errorpage.php 

DocumentRoot /var/www/demoWeb
ProxyPassMatch ^/(.*)+\.php !

    ProxyRequests Off

    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>

    ProxyPass / http://yourdomain.tld:8080/helloworld/
    ProxyPassReverse / http://yourdomain.tld:8080/helloworld/

    <Location />
        Order allow,deny
        Allow from all
    </Location>
</VirtualHost>

This is the most simple method to handle a static failover page. But also take in consideration to implement the same page for other error codes (404?), because your JBOSS can run, but your JBOSS app can be undeployed, or crashed.

share|improve this answer
    
Thanks, this looks like an ideal solution, will give it a go! –  DaveB Dec 5 '12 at 9:52

You may probably create two sites for apache and store them on /etc/apache2/sites-available. One of them is the one you already setup. The other one (let's call it "backup site") will have your php pages and a static site for the missing jboss server URLs.

Then, create a cronjob or whatever. It should check if jboss is still available. For this purpose, create a page on jboss, and call it from the cronjob. If jboss is detected as missing, then call command "a2ensite" with your "backup site" and "a2dissite" with your normal site.

The same cronjob should work the other way around: when jboss will be online again, then swap again your sites in apache.

share|improve this answer
    
Thanks for the suggestion, I will try this and make your answer as correct once its working, I was kinda hoping for a cleaner solution but I think this might be the simplest way to go –  DaveB Dec 1 '12 at 17:35
    
Having a few spare minutes I wrote a script you may use as an example. Just set the correct variables and call if from cron as required. –  eppesuig Dec 3 '12 at 22:16

The simplest solution over here will be to use Varnish as reverse proxy for apache and Jboss. Not only it will give you this functionality, as well as being the best caching server available, it will improve the performance of you site dramatically (unless your site is totally dynamic and there is nothing to cache).

Though you can find a lot of details about varnish on internet, but the specific functionality which you are looking for can be configured like this:

backend jboss { .host = "127.0.0.1"; .port = "8080"; .probe = { .url = "/"; .timeout = 3s; .interval = 5s; .window = 1; .threshold = 1; } }

backend apache { .host = "127.0.0.1"; .port = "8010"; .probe = { .url = "/"; .timeout = 3s; .interval = 5s; .window = 2; .threshold = 2; } }

sub vcl_recv { set req.backend = Jboss;

if (req.restarts == 1 || !req.backend.healthy) { set req.backend = Apache; } }

By these configs, if Jboss is down, varnish will send the traffic to apache server and serve the page which you have configured.

Hope this helped.

share|improve this answer
    
Thanks for the info, iv not come across Varnish before looks like it will do the job PLUS speed up the application! I will give it a go, but for the sake of simplicity I will implement Sacx's solution first –  DaveB Dec 5 '12 at 9:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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