How can I Set Up a Maintenance Page For My Apache Website?
I am currently running an Apache website and I would like to put it into maintenance mode so I can make updates. How can I do this?
1 Reply
If you are currently using a CMS like Wordpress, I would recommend following the steps in this guide for putting your Wordpress site into Maintenance Mode. That said, if you are just running Apache without a more generalized CMS like Wordpress, there are a few ways you can go about this.
One approach would be to script the maintenance mode directly into your website's configuration files in a way that automatically places the website into maintenance mode if the maintenance file exists. For example:
<VirtualHost *:80>
ServerName example.com
DocumentRoot "/var/www/example/htdocs"
# Redirect all request to a 503 return code when in maintenance mode
ErrorDocument 503 /maintenance/index.html
RewriteEngine on
RewriteCond /var/www/maintenance/ALL -f [OR]
RewriteCond /var/www/maintenance/%{SERVER_NAME} -f
RewriteCond %{REQUEST_URI} !=/maintenance/index.html
RewriteRule ^ - [R=503,L]
# Redirect away from the maintenance page if not in maintenance mode
RewriteCond /var/www/maintenance/ALL !-f
RewriteCond /var/www/maintenance/%{SERVER_NAME} !-f
RewriteRule ^/maintenance/index.html$ / [R,L]
</VirtualHost>
<VirtualHost *:443>
ServerName example.com
DocumentRoot "/var/www/example/htdocs"
# Redirect all request to a 503 return code when in maintenance mode
ErrorDocument 503 /maintenance/index.html
RewriteEngine on
RewriteCond /var/www/maintenance/ALL -f [OR]
RewriteCond /var/www/maintenance/%{SERVER_NAME} -f
RewriteCond %{REQUEST_URI} !=/maintenance/index.html
RewriteRule ^ - [R=503,L]
# Redirect away from the maintenance page if not in maintenance mode
RewriteCond /var/www/maintenance/ALL !-f
RewriteCond /var/www/maintenance/%{SERVER_NAME} !-f
RewriteRule ^/maintenance/index.html$ / [R,L]
</VirtualHost>
In the above example, if the files /var/www/maintenance/ALL
or /var/www/maintenance/example.com
exist, the file /var/www/maintenance/index.html
will load. You can just make that index.html file what you want the maintenance page to show. To enable maintenance mode in this case you would just touch /var/www/maintenance/ALL
or touch /var/www/maintenance/example.com
. The reason to include the option for all
is if you are hosting multiple domains on the same Linode and you want to place all websites into maintenance mode at once. To end the maintenance mode you would just run rm /var/www/maintenance/ALL
or rm /var/www/maintenance/example.com
.
This is just a super basic way to go about it, and may not be the best solution. For further reading, I would recommend taking a look at the documentation from apache.org which includes more detail as well as a few other ways to go about it. This blog post from Shell Hacks also breaks things down a little as well.
If you have any other questions or other suggestions/alternatives for creating and displaying a maintenance page, please share them here!