Apache mod-proxy 负载均衡器维护
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/942735/
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
Apache mod-proxy load balancer maintenance
提问by schickb
I have mod-proxy and mod-proxy-balancer setup as a load balancing reverse proxy. Something like this:
我有 mod-proxy 和 mod-proxy-balancer 设置作为负载平衡反向代理。像这样的东西:
<Proxy balancer://example>
BalancerMember http://hostname:8000 keepalive=on
BalancerMember http://hostname:8001 keepalive=on
</Proxy>
ProxyPass / balancer://example/
ProxyPassReverse / balancer://example/
ProxyPreserveHost on
ProxyRequests Off
Is there a simple way to set this up to show a static maintenance page when all members of the balancer group are down? I've done that with a hardware load balancer previously and it was very useful.
当平衡器组的所有成员都关闭时,是否有一种简单的方法来设置它以显示静态维护页面?我以前使用硬件负载平衡器完成了这项工作,它非常有用。
回答by Kevin Hakanson
Maybe you can use a hot standby. The example below is from the ProxyPass Directivesection where it says "Setting up a hot-standby, that will only be used if no other members are available"
也许您可以使用热备份。下面的示例来自ProxyPass Directive部分,其中显示“设置热备份,仅在没有其他成员可用时才会使用”
ProxyPass / balancer://hotcluster/
<Proxy balancer://hotcluster>
BalancerMember http://1.2.3.4:8009 loadfactor=1
BalancerMember http://1.2.3.5:8009 loadfactor=2
# The below is the hot standby
BalancerMember http://1.2.3.6:8009 status=+H
ProxySet lbmethod=bytraffic </Proxy>
回答by larsks
As an alternative to RewriteRule you can do the same thing with appropriate ErrorDocument directives. We do something like this in which the proxy server itself hosts static error pages and the "hot-standby" host is http://localhost/some-app/.
作为 RewriteRule 的替代方案,您可以使用适当的 ErrorDocument 指令执行相同的操作。我们做这样的事情,其中代理服务器本身托管静态错误页面,而“热备”主机是http://localhost/some-app/。
回答by Tarnschaf
Since your proxy seems to be the only page (probably in a VirtualHost), you can simply override error pages. Apache produces a 503 error, so this would look like:
由于您的代理似乎是唯一的页面(可能在 VirtualHost 中),您可以简单地覆盖错误页面。Apache 产生 503 错误,所以这看起来像:
# Document root is required because error documents use relative paths
DocumentRoot /var/www/html/
# Allow access to document root directory
<Directory /var/www/html/>
Order allow,deny
allow from all
</Directory>
# Actual change: If service is unavailable (no member available), show this page
ErrorDocument 503 /maintenance.html
If you want to use images inside the maintenance html, please not that you have to use absolute paths (e.g. /image.jpg) will load /var/www/html/image.jpg.
如果您想在维护 html 中使用图像,请不要使用绝对路径(例如 /image.jpg)会加载 /var/www/html/image.jpg。

