apache 如何让Apache网站503“临时宕机”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/622466/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to put Apache website to 503 "temporary down"?
提问by temoto
RFC2616, 503 Service Unavailable
RFC2616, 503 服务不可用
The server is currently unable to handle the request due to a temporary overloading or maintenance of the server
由于服务器暂时过载或维护,服务器当前无法处理请求
How to configure Apache 2.2 to serve particular name based virtualhost 503 code with custom HTML page?
如何配置 Apache 2.2 以使用自定义 HTML 页面提供基于特定名称的虚拟主机 503 代码?
采纳答案by Gumbo
You could use mod_rewrite:
您可以使用mod_rewrite:
RewriteEngine on
RewriteCond %{ENV:REDIRECT_STATUS} !=503
RewriteRule !^/down/for/maintenance$ %{DOCUMENT_ROOT}down/for/maintenance [L,R=503]
The RewriteConddirective makes sure that no additional internal error occurs when redirecting to a custom error document.
该RewriteCond指令确保在重定向到自定义错误文档时不会发生额外的内部错误。
回答by captainpete
503 Temporarily Unavailable, with trigger
503 暂时不可用,带触发器
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} !=503
RewriteCond "/srv/www/example.com/maintenance.trigger" -f
RewriteRule ^(.*)$ / [R=503,L]
If the maintenance.triggerfile exists, Apache will serve up a 503 Service Unavailableresponse. To serve up a custom "down for maintenance" page, use ErrorDocumentto specify the file, like so:
如果maintenance.trigger文件存在,Apache 将提供503 Service Unavailable响应。要提供自定义的“停机维护”页面,请使用ErrorDocument指定文件,如下所示:
ErrorDocument 503 /503_with_cats.html
Enjoy!
享受!
回答by Alex Nolasco
@temoto
@temoto
To specify a 503 for bots and a maintenance page for humans, try the following
要为机器人指定 503 和为人类指定维护页面,请尝试以下操作
RewriteEngine on
RewriteBase /
#for bots such as google
RewriteCond %{HTTP_USER_AGENT} ^.*(Googlebot|Googlebot|Mediapartners|Adsbot|Feedfetcher|bingbot)-?(Google|Image)? [NC]
RewriteCond %{ENV:REDIRECT_STATUS} !=503
RewriteRule !^/down/for/maintenance$ %{DOCUMENT_ROOT}down/for/maintenance [L,R=503]
#for humans
RewriteCond %{REMOTE_HOST} !^1\.1\.1\.1
RewriteCond %{REQUEST_URI} !^/maint.html [NC]
RewriteRule .* /maint.html [R=302,L]

