tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From André Warnier>
Subject Re: redirecting people to maintenance mode
Date Mon, 20 Aug 2012 22:06:08 GMT
Miguel González Castaños wrote:
> Dear all,
>    I have a Tomcat web server. From time to time, I need to do some 
> maintenance and want people not to interact with the Tomcat server while 
> I'm doing it. The key thing here is that the Tomcat server is up and 
> running. This is what I want to achieve:
>   - I want all people to be redirected from 80/443 port at server1 to a 
> different URL http://server2/maintenance.html except my IP address (so I 
> can check Tomcat myself).
>   - If possible, I want this to be transparent to the user, so they get 
> a http redirect showing the server1 in the client's browser, not server2 
> (but this is not that important).
>   I assume I can use iptables to redirect people to a different web 
> server, but how can I know that I need to redirect them to the 
> maintenance.html if that server is serving other web pages too?

This is a reply from someone who is not a Tomcat (nor even Java) programming specialist.

If this was to do in Tomcat itself, I believe that it would have to be done in a Valve 
which you should program yourself (using the existing Valves as a guideline).
The Valve could check on the request origin IP address, and either let the request go 
through unchanged (for your IP address), or change it to target "maintenance.html" (for 
all other IPs), depending on some condition that you could change dynamically (for 
example, whether a given "flag" file exists on the filesystem).

If it is not in a Valve (which is involved before the request is attributed to a webapp),

then you would have to do this in a servlet filter configured to run in every webapp.

But since I am not a Tomcat or Java specialist, my own preference would be to do this at 
the level of a front-end webserver like Apache httpd.
In normal circumstances, all requests get forwarded to Tomcat (via mod_proxy_http, 
mod_proxy_ajp or mod_jk).
Whenever the "maintenance flag" is set at the Apache httpd level, it does not proxy 
anymore to Tomcat (except for your IP), but returns your "maintenance.html" page.

Being myself more of a perl and mod_perl programmer, and since I am already running Apache

httpd front-ends to all my Tomcats, I use a custom mod_perl module to do exactly that kind

of thing.

Apache httpd can have its configuration reloaded "gracefully" without stopping Apache 
httpd. So you could probably do this without mod_perl, using an alternative httpd.conf 
configuration file and conditional rewrite rules.  I just created a custom mod_perl module

because it was fun.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message