Solved

Apache: Taking a Site Down for Maintenance

Posted on 2008-06-09
16
1,015 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
ID: 21750561
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
ID: 21751989
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
ID: 21752295
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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

Author Comment

by:headzoo
ID: 21752348
@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
ID: 21752365
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
ID: 21752385
"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
ID: 21752495
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
ID: 21752568
@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
 

Author Comment

by:headzoo
ID: 21752637
"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
ID: 21752665
@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
ID: 21753063
@ 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
ID: 21753119
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
ID: 21753308
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
ID: 21753370
@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
ID: 21753391
<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
ID: 21753900
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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MDB2 Error: not found 4 188
Ubuntu 14 with Apache 7 75
PHP in Apache server 20 97
Updating PHP in Windows Server 2012 r2 22 165
Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

825 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