I have the following Apache config, which displays a 503 Service Unavailable error to all visitors except for my IP address:
ErrorDocument 503 /503.html
RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^127.0.0.1$
RewriteCond %{REQUEST_URI} !^/503.html$
RewriteRule .* - [R=503]
This is so that I can carry out maintenance on my site without errors showing for users. (I'm using my actual IP, not 127.0.0.1
.)
However, to turn this off or on I need to comment/uncomment all the lines, or completely remove it. On my other server running nginx I used a geo clause with a variable (as seen in this question). So I can just change default
from 0
to 1
to turn it on.
Is there a way to do something similar in Apache?
If you don't want to restart Apache to change settings (which is a requirement for changes in the configuration) and you're not using
.htaccess
files (which you don't want to, really)You could set up what we do (via our loadbalancer usually though), a test for a maintenance status e.g. by adding a test
where a maintenance window starts by creating a maintenance.txt file (e.g. with
touch maintenance.txt
) on the otherwise live site.Look into how Debian/Ubuntu configure Apache. They use configuration excerpts for sites, modules and general configuration stored in files in
/etc/apache2/{mod|sites|conf}-available
that gets symlinked into/etc/apache2/{mod|sites|conf}-enabled
to activate it. These*-enabled
directories areInclude
ed in the main config file. Additional, they havea2Xen
anda2Xdis
commands that just create the symlink or delete it for easy maintenance.HBruijn's answer is the best but here's another option I just discovered that works:
Then the
0
can be changed to1
to toggle it on.