It’s nice to let your users know what is going on whenever an #ApacheServer needs to go into #MaintenanceMode.
No one likes it when a site goes down, but it is worse when there is no feedback as to what is going on. A maintenance page displayed during the downtime is most helpful.
Obviously, this is only going to work for minor updates that don’t involve taking down the HTTP server daemon. Even then, it could be useful to warn people off before a server reboot, for example.
This is a pointer to instructions for use on an Apache server, so that is the first prerequisite. It relies upon the Apache rewrite mechanism to work. I’ve not worked with nginx, so I cannot attest to the usability of anything here to that platform.
I’ve tested this on WordPress, but you can adapt this to Joomla, Drupal and other sites as well. Since Apache itself must be running, this probably won’t make a lot of sense for static websites that don’t have database engines in the background.
The original excellent instructions are at Shell Hacks in the article “Redirect Site to Maintenance Page using Apache and HTAccess“. There really are only a couple of things I would add: VPS defaults will likely differ from shared hosting defaults, and the article did not mention that the Apache configuration file likely is in /etc/apache2/apache2.conf on your VPS.
To sum it up, there are 3 parts:
- Create the maintenance.html. This will be the page the visitor sees.
- Create the maintenance.enable file. The presence of this file triggers maintenance mode. You can rename it to maintenance.enable.not between times.
- Add Rewrite statements to either .htaccess or apache2.conf.
Whether you use .htaccess or Apache’s apache2.conf is up to you. Keep in mind that shared hosting sites usually encourage the former, but VPS defaults might interfere with that mechanism. In the WordPress DigitalOcean droplet, the Apache directives were more restrictive, but I used the opportunity to clean up the .htaccess quite a bit using other mechanisms, this only being one such item.
The Apache configuration file is the one usually recommended anyhow, as .htaccess hits can slow down your system.
Other than customization of the maintenance page, the only real departure from the instructions was that I left out the line:
Header Set Cache-Control "max-age=0, no-store"
If I’m reading this correctly (and I could well be mistaken), this line would get invoked every time a user hit the site regardless of whether or not it was in maintenance mode. This seemed like overkill to me, but perhaps on a much bigger site it makes sense (which is still questionable, since it would add yet more to the load)?
At any rate, that article is probably one of the most straight-forward Apache articles I’ve ever read. I’m not joking. Far too many try to explain far too much or assume you know some other piece of information without which none of it will ever work.