私の解決策:
- メンテナンス モード テンプレートを作成し、urlconf を介してリンクします。これにより、/under-maintenance/ にアクセスするとメンテナンス ページが表示されます。
- 次に、「maintenance-mode-on」ファイルの存在をテストするように apache を構成し、存在する場合は、メンテナンス モード ページの URL への 302 リダイレクトを実行します。
- 「maintenance-mode-off」ファイルが存在する場合は、メンテナンス モードの URLからホームページにリダイレクトするように Apache を構成します。
- メンテナンス モード オンとメンテナンス モード オフの間のファイルの切り替えを容易にするファブリック スクリプト。
Apache 構成ファイルの関連セクションは次のとおりです。
RewriteEngine On
# If this file (toggle file) exists then put the site into maintenance mode
RewriteCond /path/to/toggle/file/maintenance-mode-on -f
RewriteCond %{REQUEST_URI} !^/static.*
RewriteCond %{REQUEST_URI} !^/admin.*
RewriteCond %{REQUEST_URI} !^/under-maintenance/
# redirect to the maintenance mode page
RewriteRule ^(.*) /under-maintenance/ [R,L]
#If not under maintenance mode, redirect away from the maintenance page
RewriteCond /path/to/toggle/file/maintenance-mode-off -f
RewriteCond %{REQUEST_URI} ^/under-maintenance/
RewriteRule ^(.*) / [R,L]
次に、ファブリック スクリプトの関連部分:
env.var_dir = '/path/to/toggle/file/'
def is_in_mm():
"Returns whether the site is in maintenance mode"
return files.exists(os.path.join(env.var_dir, 'maintenance-mode-on'))
@task
def mm_on():
"""Turns on maintenance mode"""
if not is_in_mm():
with cd(env.var_dir):
run('mv maintenance-mode-off maintenance-mode-on')
utils.fastprint('Turned on maintenance mode.')
else:
utils.error('The site is already in maintenance mode!')
@task
def mm_off():
"""Turns off maintenance mode"""
if is_in_mm():
with cd(env.var_dir):
run('mv maintenance-mode-on maintenance-mode-off')
utils.fastprint('Turned off maintenance mode.')
else:
utils.error('The site is not in maintenance mode!')
これはうまく機能しますが、メンテナンス モード中の Django 処理リクエストに依存します。静的ファイルを提供するだけでいいでしょう。