自动 Apache 服务器维护页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/98106/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 16:44:19  来源:igfitidea点击:

Automated Apache Server Maintenance Page

apachemaintenance

提问by JavadocMD

I have a website running on a Linux/Apache/Tomcat stack that needs to be automatically taken offline every few months for server maintenance, which will last an arbitrary amount of time. What are some options for getting Apache to put up and take down a "server maintenance" page?

我有一个在 Linux/Apache/Tomcat 堆栈上运行的网站,它需要每隔几个月自动离线以进行服务器维护,这将持续任意时间。有哪些选项可以让 Apache 建立和取消“服务器维护”页面?

I need to be able to control this via shell script. (The answers that Google provided revolve around manually editing the server configuration, and I don't want to be in the office at 3 am!) I suppose I could make the script drop in an .htaccess file and delete it when it's done, but that seems less than graceful.

我需要能够通过 shell 脚本来控制它。(Google 提供的答案围绕手动编辑服务器配置展开,我不想凌晨 3 点在办公室!)我想我可以将脚本放入 .htaccess 文件中并在完成后将其删除,但这似乎不够优雅。



Answer commentary:

回复评论:

Mike's answerlooks like the best-practices answer, although what I'll do is probably more like Dan's answerbecause the third-party hosting provider controls the load balancer and I don't want to deal with that mess. Thanks!

Mike 的回答看起来像是最佳实践的回答,尽管我会做的可能更像Dan 的回答,因为第三方托管服务提供商控制着负载均衡器,而我不想处理那些烂摊子。谢谢!

回答by Mike Starov

We have a setup that does just that but it includes more than just apache. There is a loadbalancer and two servers behind it. Both web servers serve website using Apache and one of them has an additional virtual host that serves simple HTML maintenance page. The load balancer has a virtual HTTP service that redirects requests to real servers. This virtual service has three real servers: two are actual servers and third is a virtual IP on second server that points to maintenance page. The real servers are weighted with third having the least possible weight and the load balancer uses fixed weighting algorithm. So when real websites go offline for any reason all requests go to maintenance host and users see the nice error page with a phone number. In fact I use a small script to check the health of real servers, so the maintenance page displays as soon as there is any sign of trouble.

我们有一个可以做到这一点的设置,但它不仅仅包括 apache。后面有一个负载均衡器和两台服务器。两个 Web 服务器都使用 Apache 为网站提供服务,其中之一有一个额外的虚拟主机,用于提供简单的 HTML 维护页面。负载均衡器有一个虚拟 HTTP 服务,可以将请求重定向到真实服务器。该虚拟服务具有三个真实服务器:两个是实际服务器,第三个是指向维护页面的第二个服务器上的虚拟 IP。真实服务器的权重为第三个,权重最小,负载均衡器使用固定加权算法。因此,当真实网站因任何原因离线时,所有请求都会发送到维护主机,用户会看到带有电话号码的错误页面。实际上我使用一个小脚本来检查真实服务器的健康状况,

PS. I use Load Master 1500 for loadbalancer.

附注。我使用 Load Master 1500 作为负载均衡器。

回答by Dan

it's pretty easy to start up Apache with a custom config file. On my system:

使用自定义配置文件启动 Apache 非常容易。在我的系统上:

httpd -f <config>

I use this regularly in combination with a shell script an an extremely simple config as a maintenance placeholder. The script simply stops my regular Apache, and starts this.

我经常将它与 shell 脚本结合使用,这是一个非常简单的配置作为维护占位符。该脚本只是停止我的常规 Apache,然后启动它。

回答by BCS

make 2 config files and swap them back and forth

制作 2 个配置文件并来回交换它们

If only a little bit of the file will change, merge them with come sort of preprocessor and generate both the standard and the "off-line" versions from one source and swap between those.

如果文件只有一点点会发生变化,请将它们与一种预处理器合并,并从一个源生成标准和“离线”版本,并在它们之间进行交换。

IIRC the apache config files are build using CPP anyway

IIRC apache 配置文件无论如何都是使用 CPP 构建的

回答by BCS

We have done something similar. We have an index.html that redirects to our main site page. When we have maintenance we run a script that changes the redirect in the html file. Then we through the script in cron and viola automatic maintenance window.

我们做过类似的事情。我们有一个 index.html 重定向到我们的主站点页面。当我们进行维护时,我们运行一个脚本来更改 html 文件中的重定向。然后我们通过cron 和viola 自动维护窗口中的脚本。

Hope that helps!

希望有帮助!