2

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?

3 Answers 3

4

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

RewriteCond ^/maintenance.txt -f 

where a maintenance window starts by creating a maintenance.txt file (e.g. with touch maintenance.txt) on the otherwise live site.

0

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 are Includeed in the main config file. Additional, they have a2Xen and a2Xdis commands that just create the symlink or delete it for easy maintenance.

2
  • I don't want to disable a site completely, I want to serve a 503 to everyone except me temporarily. Mar 28, 2016 at 21:51
  • This is a way to quickly add and remove configuration parts. You put your config fragment into a file and you can activate or deactivate this fragment quickly by creating or removing a single symlink. However, for this specific problem, I like HBruijns method better anyway.
    – Sven
    Mar 28, 2016 at 21:53
0

HBruijn's answer is the best but here's another option I just discovered that works:

RewriteCond 1 0

Then the 0 can be changed to 1 to toggle it on.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .