5

I've set up Apache to send requests to camera.example.com to an a webcam accessible via an IP address not associated with the server Apache's running on, using ProxyPass:

[camera] -- [nat / prt frwrd] -- [11.22.33.44]-- [internets] -- [webserver]

Relevant entry in the Apache's virtual host directive for the 'example.com':

<VirtualHost *>
  ServerName camera.example.com
  ProxyRequests Off
  ProxyPass / http://11.22.33.44/
  ProxyPassReverse / http://11.22.33.44/
</VirtualHost>

Works like a charm, however, the camera is not always turned on. In that case, instead of having Apache serve a 'not found' error upon visiting my camera , I'd like it to serve an alternative web page.

Would it be possible to set some sort of 'fall-back' address in case the first one (the camera's) is not available?

3 Answers 3

14

you can use load balancing capability of apache, it has automatic failover built-in as well.

your config would look as follows:

ProxyPass / balancer://hotcluster/
<Proxy balancer://hotcluster>
 BalancerMember http://addres.of.the.camera timeout=15 retry=300
 BalancerMember http://address.of.backup.server status=+H
</Proxy> 

you just mark backup-server with +H - hot standby. as long as camera answers [ in timeout sec ] - traffic is sent to it; if it does not - apache starts sending traffic to the backup machine, and will check camera every retry seconds.

0
0

If this is a public IP address, certain DNS providers will ping your IP address, and failover to a backup IP address if it is not available. We use dnsmadeeasy.com for this.

One thing to be aware of however, is that it may only check every 5 minutes or so, so failover and failback are not instantaneous.

0

This config was not failing over for me, I think it is only activated if a timeout is reached, but what about 500 errors?

I set it up differently, according to apache docs: https://httpd.apache.org/docs/trunk/howto/reverse_proxy.html https://httpd.apache.org/docs/trunk/mod/mod_proxy_hcheck.html

ProxyHCExpr ok234 {%{REQUEST_STATUS} =~ /^[234]/}

<Proxy balancer://hotcluster>
  BalancerMember http://addres.of.the.camera timeout=15 hcmethod=HEAD hcexpr=ok234
  BalancerMember http://address.of.backup.server status=+H
</Proxy>

ProxyPass / balancer://hotcluster/
ProxyPassReverse / balancer://hotcluster/

<Location "/balancer-manager">
SetHandler balancer-manager
Require host localhost
</Location>

The last location (balancer-manager) is only for debugging/troubleshooting, and is a great tool to find out the real behavior of your balancer.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .