Apache mod-proxy 负载均衡器维护

发布于 2024-07-23 05:39:48 字数 433 浏览 8 评论 0原文

我将 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

是否有一种简单的方法可以将其设置为在平衡器组的所有成员都关闭时显示静态维护页面? 我之前已经使用硬件负载平衡器做到了这一点,它非常有用。

I have mod-proxy and mod-proxy-balancer setup as a load balancing reverse proxy. Something like this:

<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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

dawn曙光 2024-07-30 05:39:48

也许您可以使用热备。 下面的示例来自 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>

Maybe you can use a hot standby. The example below is from the ProxyPass Directive section where it says "Setting up a hot-standby, that will only be used if no other members are available"

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>
千と千尋 2024-07-30 05:39:48

作为 RewriteRule 的替代方案,您可以使用适当的 ErrorDocument 指令执行相同的操作。 我们做这样的事情,其中​​代理服务器本身托管静态错误页面,“热备用”主机是 http:// /localhost/some-app/

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/.

你怎么这么可爱啊 2024-07-30 05:39:48

由于您的代理似乎是唯一的页面(可能在虚拟主机中),因此您可以简单地覆盖错误页面。 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

如果您想在维护 html 中使用图像,请注意您必须使用绝对路径(例如 /image.jpg)来加载 /var/www/html/image。 .jpg。

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:

# 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文