如何将Apache网站放到503“临时停机”?

时间:2022-06-25 16:06:45

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代码?

3 个解决方案

#1


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 RewriteCond directive makes sure that no additional internal error occurs when redirecting to a custom error document.

RewriteCond指令确保重定向到自定义错误文档时不会发生其他内部错误。

#2


503 Temporarily Unavailable, with trigger

RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} !=503
RewriteCond "/srv/www/example.com/maintenance.trigger" -f
RewriteRule ^(.*)$ /$1 [R=503,L]

If the maintenance.trigger file exists, Apache will serve up a 503 Service Unavailable response. To serve up a custom "down for maintenance" page, use ErrorDocument to specify the file, like so:

如果maintenance.trigger文件存在,Apache将提供503 Service Unavailable响应。要提供自定义的“down for maintenance”页面,请使用ErrorDocument指定文件,如下所示:

ErrorDocument 503 /503_with_cats.html

Enjoy!

#3


@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]

#1


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 RewriteCond directive makes sure that no additional internal error occurs when redirecting to a custom error document.

RewriteCond指令确保重定向到自定义错误文档时不会发生其他内部错误。

#2


503 Temporarily Unavailable, with trigger

RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} !=503
RewriteCond "/srv/www/example.com/maintenance.trigger" -f
RewriteRule ^(.*)$ /$1 [R=503,L]

If the maintenance.trigger file exists, Apache will serve up a 503 Service Unavailable response. To serve up a custom "down for maintenance" page, use ErrorDocument to specify the file, like so:

如果maintenance.trigger文件存在,Apache将提供503 Service Unavailable响应。要提供自定义的“down for maintenance”页面,请使用ErrorDocument指定文件,如下所示:

ErrorDocument 503 /503_with_cats.html

Enjoy!

#3


@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]