views:

308

answers:

4

Occasionally when I try to open a site I will see a page saying smth like "This site is offline for maintenance" and then some comments follow on how long it would presumably take. Stack Overflow does that too.

How does it work? I mean if the site is shut down who replies to my HTTP request and serves this page?

+18  A: 

There is a trick in asp.net where you place a file called

App_Offline.htm

All requests will go to this, until the page is deleted.

For other environments you can often just change where the server points, or another such plan.

-- Edit

A server-agnostic approach is achieved through something like load-balancing.

Under the hood you can send the requests to a given internal server. You may then decide to point all requests to your server 'a', which you configure to show the 'downtime' page. Then, you make changes to server 'b', confirm it as successful, and point all requests to 'b'. Then you update 'a', and let requests go to both.

Noon Silk
+10  A: 

In ASP.NET (and ASP.NET MVC as Stackoverflow uses) this is provided by the app_offline.htm feature. This works simply by forwarding all ASP.NET requests to the app_offline.htm file.

Incidentally the copy Web Site tool in ASP.NET performs the process of placing this file in the root of the web app, copyies the Web site files and then deletes this file.

Strategies for other technologies are discussed here.

RichardOD
+2  A: 

The apache reverse proxy server can be configured to send that response - if it is being used as part of that architecture.

techzen
+4  A: 

In apache you may use a .htacces file with this content.

order deny,allow
allow from 192.168.1.151
deny from all

ErrorDocument 403 404.html
ErrorDocument 404 404.html
ErrorDocument 500 404.html

This will deny access to everyone except one IP and serve a static 404.html file.

This works in the case you only have one server without load-balancing and other stuff. Should work for load-balancing too though.

Quamis