Solved

Apache: Taking a Site Down for Maintenance

Posted on 2008-06-09
16
1,012 Views
Last Modified: 2012-06-21
Hi,
What's the best way to show a "We'll be back soon" message to site visitors when I need to take the site down for maintenance?

If my site is at mysite.com, I need all visitors to see the same plain HTML file no matter what URL they try to visit, e.g. mysite.com, mysite.com/accounts/settings, etc.

It would be great if I could simply uncomment a couple lines in the httpd.conf to do this, and then comment them again to bring the site back up.
0
Comment
Question by:headzoo
  • 7
  • 5
  • 4
16 Comments
 
LVL 57

Expert Comment

by:giltjr
Comment Utility
Define "taking a site down for maintenance".  Are you actually stopping Apache?  If so there is nothing you can do.

If you are not taking Apache down, what are you doing to take it out of service?

0
 

Author Comment

by:headzoo
Comment Utility
HI giltjr,
No, I wouldn't be shutting down Apache. One possible scenario is upgrading the website software (Not the HTTP server), which may take an hour. I'd like to show a message to the visitors that the site is down for  upgrades, and it'll be back up shortly.
0
 
LVL 1

Expert Comment

by:alamo25
Comment Utility
I would also be interested in learning a good solution to this issue so I am piggy backing on this request.  I have mix feelings with modifying the .htaccess file to redirect to a maintenance page.  In our location we have 3 apache servers hosting several environments (Dev, QA & Training for ex.).  Our base config file references on the host name, not the IP.  If I make a change or add an .htaccess file in the web root directory with the following,

1.      RewriteEngine On  
2.      RewriteBase /  
3.      RewriteCond %{REMOTE_ADDR} !^11\.111\.111\.111  
4.      RewriteCond %{REQUEST_URI} !^/maintenance\.html$  
5.      RewriteRule ^(.*)$ http://domain.com/maintenance.html [R=307,L]

can I expect to have traffic re-directed to the maintenance page, while still allowing us to perform maintenance.  In the base config file the AllowOveride is set to NONE.  In order to use .htaccess file I would have to make this change to every .htaccess file in every one of those environments.  Is it possible just to have the DNS server redirect traffic to a maintenance page on another box and allow traffic via a specific IP to enter the environments to perform maintenance and testing.

Thanks
0
 

Author Comment

by:headzoo
Comment Utility
@alamo25

"Is it possible just to have the DNS server redirect traffic to a maintenance page on another box"

I've seen that back fire in the past. Often times people will still be seeing the maintenance page for days because of DNS caching either on their PC, or at their ISP.
0
 
LVL 57

Expert Comment

by:giltjr
Comment Utility
I'm fairly lazy so what I would do is setup my DirectoryIndex like:

     DirectoryIndex maintenance.html index.html

Then create the file maintenance.html.XXX with my "out of service" message.  Then when I do maintenance just rename it to maintenance.html.  Once maintenance is done, rename it back.

You can't do this via DNS because of the caching done out in the Internet.
0
 

Author Comment

by:headzoo
Comment Utility
"DirectoryIndex maintenance.html index.html "

I'm guessing you would need to have a rewrite rule in the .htaccess to point all requests (even for sub directories) to that maintenance.html page?
0
 
LVL 57

Expert Comment

by:giltjr
Comment Utility
Not knowing your exact setup, you should not need a re-write rule.  What is your default page name?  Are you using virtual hosting?

If you are using virtual hosting you just need to add the DirectoryIndex to the virtual host definition.

0
 
LVL 1

Expert Comment

by:alamo25
Comment Utility
@headzoo, Thanks, Then I guess I could using .htacces is still my only choice to do a simple redirect -

Use Redirects during maintenance(to redirect from index.html to tempmessage.html) or to redirect from an old file to a new file.

In order to redirect from http://yoursite.com/old/file.html to http://yoursite.com/new/file.html, simply put this line in your .htaccess file.

                                 Redirect /old/file.html http://yoursite.com/new/file.html

The /old is relative to the root of your website. i.e at http://yoursite.com/old.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:headzoo
Comment Utility
"Not knowing your exact setup, you should not need a re-write rule.  What is your default page name?  Are you using virtual hosting?"

No, I'm using my own server. And yes, I imagine you would need rewrite rules. Here's why:

You put maintenance.html in your webroot, i.e. /var/www/maintenance.html
That works fine so long as people are visiting http://mysite.com
However that doesn't work if people are visiting http://mysite.com/some/sub/directory

So you would need an .htaccess in the root dir, i.e. /var/www/.htaccess with the following:

RewriteEngine On
RewriteRule . maintenance.html
0
 

Author Comment

by:headzoo
Comment Utility
@alamo25

See my post above. I wouldn't use redirects because they're slower. Using an .htaccess like this will do the trick:

RewriteEngine On
RewriteRule . maintenance.html

That forces Apache to serve up the maintenance.html page for every request.
0
 
LVL 1

Expert Comment

by:alamo25
Comment Utility
@ Headzoo

What if the site is an internal portal, not a public domain site where all users Login to gain access.  I would need the exception to allow the developers to do maintenance and test on that box correct?
0
 
LVL 1

Expert Comment

by:alamo25
Comment Utility
One other point with regards to the exception, our base config file does not reference an IP in the Directory Directive, just the hostname, will that make a difference in how the maintenance page is served while still allowing access via the IP?
0
 
LVL 57

Accepted Solution

by:
giltjr earned 500 total points
Comment Utility
Well, then what you could do is easily change the document route for the virtual server and have a custom 404 message for those users have have bookmarked a page that is "beyond" the default page.

Then you issue the command "apachecntl restart" and Apache will re-read the conf file without terminating any current connections.

So
<virtualserver *:80>
servername www.mysite.com
alias mysite.com
DocumentRoot /myroute
</virtualserver>

becomes something like:

<virtualserver *:80>
servername www.mysite.com
alias mysite.com
DocumentRoot /downformaint
ErrorDocument 404 /maint.html
</virtualserver>
0
 

Author Comment

by:headzoo
Comment Utility
@alamo25

If you know the IP address of the developers, you could do something like this:

RewriteEngine On
RewriteCond %{REMOTE_ADDR} !24.0.0.1|23.0.0.3
RewriteRule . maintenance.html [L]

With that, the users with IP addresses 24.0.0.1 or 23.0.0.3 can access the system. Everyone else will get served the maintenance.html file.
0
 

Author Comment

by:headzoo
Comment Utility
<virtualserver *:80>
servername www.mysite.com
alias mysite.com
DocumentRoot /downformaint
ErrorDocument 404 /maint.html
</virtualserver>

And /downformain would simply have no files in it, thus always generating a 404? Since Apache would send a 404 status code in the header, I wonder what impact that could have, if any.
0
 
LVL 57

Expert Comment

by:giltjr
Comment Utility
It will have some additional overhead.  How much it impacts you depends on how many hits you get for that virtual server.  If you are doing 10 hits per second, not much, if you are doing 10,000 hits per second, a lot.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now