我的解决办法:
- 通过URL配置创建一个维护模式模板,并链接到它,所以当访问/维修不足/显示维护页面。
- 然后,配置apache以测试是否存在'maintenance-mode-on'文件,如果存在,请将302重定向到维护模式页面的url。
- 如果存在“维护模式关闭”文件,则配置apache将从重定向到主页的维护模式URL。
- 结构脚本,便于在维护模式开启和维护模式关闭之间切换文件。
下面是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的处理维护模式期间的请求;这将是很好的服务一个静态文件。
This [question](http://stackoverflow.com/questions/6237514/write-to-a-remote-file-with-fabric)可能有关。我对织物不太了解,我不是故意粗鲁,但是,没有使用SSH并且更改一个设置线相当容易?这是一个远程方法 – 2011-06-10 16:58:31
由于浏览器缓存,我发现Garth Humphreys的方法并不好。它导致以下情况之一: - 在维护模式期间看到非维护模式页面 - 未处于维护模式时看到维护模式页面 我会将我的调整解决方案放在单独的答案中。 – seddonym 2013-05-24 10:51:06