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 have a server with multiple domains. Both http (apache) traffic and http-alt (tomcat) traffic.

If/when I take the server down, I'd like to be able to redirect people to a temporary 'undergoing maintenance' page, regardless of their destination URL/port.

How can this be achieved? Do I need tomcat running on the secondary server or is there a way to catch all and redirect via some method I'm not aware of? I've tried simply forcing all 80/8080 traffic to the secondary server, but depending on the URL it doesn't resolve, and it never resolves when trying to access :8080/whatever. Any ideas?

EDIT (update): I have successfully achieved this catch all for any domain and anything port 80 traffic using _default_ vhost, but it's still not catching anything on 8080, even though I am specifying:

<VirtualHost _default_:*>
    DocumentRoot /var/www
    ServerName host
    ServerAlias *
    ErrorDocument 404 /index.html
</VirtualHost>

Anyone know why or how to?

EDIT (update 2): using tomcat's error-code

in /etc/tomcat/web.xml I added

<error-page>
    <error-code>404</error-code>
    <location>/WEB-INF/index.html</location>
</error-page>

I am able to get it to work now for the root of tomcat http://domain.com:8080 but nothing for any general 404 like http://domain.com:8080/nonexistentpath

Any ideas? Thanks

share|improve this question
1  
Use IP Tables, not you Apache config. I would give more information, but I'm no expert. Take a look at cyberciti.biz/faq/linux-port-redirection-with-iptables. –  David W May 20 '12 at 21:14
    
Thanks, it actually is working now. I changed /WEB-INF/index.html to /index.html and also added the <error-code>500</error-code> as well. I will look into using IP Tables as well, thanks for the tip. –  TryTryAgain May 20 '12 at 21:16

1 Answer 1

up vote 0 down vote accepted

As noted in my updates to the question and stated in the comments above:

To handle the port Apache (port 80) 404's, I used the following in the Apache config:

<VirtualHost _default_:*>
    DocumentRoot /var/www
    ServerName host
    ServerAlias *
    ErrorDocument 404 /index.html
</VirtualHost>

To handle them in Tomcat (8080, in my case), in /etc/tomcat/web.xml i added:

<error-page>
    <error-code>404</error-code>
    <location>/index.html</location>
</error-page>

The only other problem I came across is that the tomcat 404 would not display on IE. I ended up needing to add additional data to the page in form of comments to add some weight to the file for IE to display my custom page instead of it's own. How silly.

I hope this helps someone else, in the future.

share|improve this answer

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.