Sometimes you need to shut some web-services down for a while to do some maintenance works. Of course, you have warned all users about the scheduled downtime period, but what if it’s just impossible to inform all potential victims, e.g. every potential visitor of some web-site that won’t be working? It’s a good idea to take care of those people (or bots) and to let them know what’s going on and when their websites is up. It’s easy to make a web-server showing some maintenance notice, but what if you need to shut the server down completely? If it’s a single server, not a cluster, what visitors will see when you shut it down? They will wait for the page to be loaded, but a message saying that the connection is timed out will be the only reward for their patience. It would be much better to let them know that you’re apologizing for inconveniences, working hard to fix the issue and have some prognosis on when it’ll be okay.
So, let’s involve some spare web-server (supposedly, you have some, don’t you?) and make it showing some calming message for users and visitors of their web-sites. It’s quite easy when you have a spare web-server connected to the same network or vlan, there are just few simple steps that needed to be performed.
Step 1: creating the announcement page
Maybe one of your colleagues has already wrote an announcement and published it where your users can read it, didn’t they? If yes – let’s take the text for the notice from there, if not – let’s write the message by ourselves. Of course, as we need it to be formatted properly, we should add some HTML-tags.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<!doctype html> <title>Site Maintenance</title> <style> body { text-align: center; padding: 150px; } h1 { font-size: 50px; } body { font: 20px Helvetica, sans-serif; color: #333; } article { display: block; text-align: left; width: 650px; margin: 0 auto; } a{ color: #dc8100; text-decoration: none; } a:hover { color: #333; text-decoration: none; } </style> <article> <h1>We’ll be back soon!</h1> <div> <p>Sorry for the inconvenience but we’re performing some planned maintenance at the moment. If you need to you can always contact our support team by sending a message to <a href="mailto:support@tuchacloud.com"></a> or dialing +380445835583.</p> <p>Works can take some time, but we’ll bring this website up before 4:20 of April 20th, 2015 (GMT)!</p> <p>— The Team of <a href="https://tuchacloud.com/">TuchaCloud</a></p> </div> </article> |
Lots of thanks to Pitch for the sample!)
Now let’s put this page somewhere, for example to /var/www/vhosts/13.13.13.13/maintenance.html
.
Step 2: configuring nginx
No, I won’t believe you don’t know how to install nginx on your operating system. So let’s suppose you’ve done it already and we only need to add the following server stanza to its configuration:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
server { listen 13.13.13.13:80 default_server; access_log /var/log/nginx/13.13.13.13-maintenance-access.log; error_log /var/log/nginx/13.13.13.13-maintenance-error.log; location ~ .* { return 503; } error_page 503 /maintenance.html; location = /maintenance.html { charset utf-8; # in case you'd like to use it root /var/www/vhosts/13.13.13.13/; break; } } |
Step 3: interception
If the spare server is in the same IP-network with our 13.13.13.13, it’s easy to make it receive all requests intended for 13.13.13.13, just add an according alias to the network interface, for example:
1 |
ifconfig eth0:0 13.13.13.13/24 |
Well, that’s all! Just don’t forget to update the information on the maintenance page when you realize you won’t bring the service up in time you’ve promised! 🙂
Just a cheat-sheet for Apache HTTPd 🙂