[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1048
  • Last Modified:

Apache: Taking a Site Down for Maintenance

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
headzoo
Asked:
headzoo
  • 7
  • 5
  • 4
1 Solution
 
giltjrCommented:
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
 
headzooAuthor Commented:
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
 
alamo25Commented:
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
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
headzooAuthor Commented:
@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
 
giltjrCommented:
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
 
headzooAuthor Commented:
"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
 
giltjrCommented:
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
 
alamo25Commented:
@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
 
headzooAuthor Commented:
"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
 
headzooAuthor Commented:
@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
 
alamo25Commented:
@ 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
 
alamo25Commented:
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
 
giltjrCommented:
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
 
headzooAuthor Commented:
@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
 
headzooAuthor Commented:
<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
 
giltjrCommented:
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now