简体   繁体   中英

Apache mod-proxy load balancer maintenance

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.

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>

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

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 (eg /image.jpg) will load /var/www/html/image.jpg.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM