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

Note: I am new to this situation!

How do we manage to to redirect every request during maintenance to a page which says the site is under maintenance mode?

I want to automate this process (through cron):

  1. Shutdown apache
  2. Do maintenance (During this time every request should be redirected to the maintenance page)
  3. Start apache

In point 2 how do I redirect each request when apache is down or how do people manage this (automated)? Appreciate your responses.

Thanks

share|improve this question
    
Looking for ideas like this? serverfault.com/questions/23485/… –  Kara Marfia Jul 20 '10 at 18:19
1  
RewriteRule .* 503.php [L] –  Nerdling Jul 20 '10 at 18:39

3 Answers 3

If you just want to make the sites unacessible during maintenance and use one file per virtual host like ubuntu and debian do (/etc/apache2/sites-available and sites-disabled) you can just disable the sites removing the links from sites-available (or moving the files out). You can also create a 'catch all' site and enable it showing a 'maintenance message'.

Other option is to use iptables to redirect all traffic on the http port to another port on the server, where you can run a secondary webserver (lighttpd or nginx or anything really small that can serve static html pages). The rule would be:

iptables -t nat -A PREROUTING -p tcp -i ethX -d <server ip> –dport 80 -j DNAT –to <server ip>:<new port>

You can also redirect to another server/port completely.

share|improve this answer

Apache needs to remain running to serve websites, but you can configure it to send all requests to a maintenance webpage using the DocumentRoot directive. Assuming you create a page for maintenance notification inside of a maintenance directory, it would look like this:

Normal Operations:

DocumentRoot "/var/www/html"
#DocumentRoot "/var/www/html/maintenance"

Maintenance Operations: just comment out the normal and uncomment the maintenance line:

#DocumentRoot "/var/www/html"
DoucmentRoot "/var/www/html/maintenance"

Then just reload Apache to activate the changes: /etc/init.d/httpd reload. When you finish, just reverse the process.

Note that if you have multiple VirtualHosts you would need to make that DocumentRoot change for each one. There might be (probably is) a simpler method - for a simple setup this is what I do.

share|improve this answer
    
What if you have to pull down your apache, how do you redirect requests? –  Vishal Jul 20 '10 at 18:47
2  
If you HAVE to pull down apache, you need to have at least some server intercepting requests in that time. Either by another server temporarily answering on that IP address, or a front end load balancer redirecting traffic to a "we're in maintenance" web server. –  GruffTech Jul 20 '10 at 18:49

I can not talk about Apache, but here is how I do it in IIS (which, indicentally, has IMHO a better interface for that).

  • I have the website in a folder (OBVIOUSLY)
  • I have another site in another folder that is the "maintenance site".
  • I just change the folders on the site before maintenance.

IIS / ASP.NET also have a nice mechanism where a "block file" turns the whole site into maintenance mode. This is done by putting a page "app_offline.htm" into the site's root folder. The negatie side odf that is that you can not test the site under another URL while this is in (which may be good for a last internal check that all things work). So, I went over to have a maintenance site.

Having a separate folder and redirecting the site is IMHO the fastest way.

share|improve this answer
1  
What if you have a lot of virtual hosts served by a single server instance? Do you put lots of app_offline.htm for each of them? –  halp Jul 20 '10 at 18:26
    
That depends. App_offline in a host - depends. Do I maintain all the sites at the same time? Normally not. Then naturally no app_offline in the ones not under maintenance. –  TomTom Jul 20 '10 at 18:52

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.