How can I setup an apache mod-proxy server to server content from a seperate designated server, in a way that I can change which server to serve content from without restarting apache?

The content server will change periodically, either for maintenance, or because of failure.

I have an app that does not need to be in a cluster, but I want to have a static version of the webpage display in the event the main app server crashes.

I also want the option to update the codebase on the server test it and then switch out the old live server.

I've set up mod_proxy using

ProxyPass / http://appserver.com
ProxyPassReverse / http://appserver.com

this works but seams to require a restart with different settings to change the direction. which defeats the purpose of using it on a live server.

I've also tried mod_balencer which works great for the failover but requires an apache restart to set it back to serving up the main app server when it's backup.

     ProxyPass / balancer://hotcluster/
     <Proxy balancer://hotcluster>
            BalancerMember http://dyn:80 loadfactor=1
            BalancerMember http://basic:80 status=+H
            ProxySet lbmethod=bytraffic

Is there a way I can set what the current app server is without restarting apache?

  • Note that, at least as of 2.5 years after this question was asked, mod_proxy_balancer in Apache 2.2 seems to retry "down" servers within 60 seconds, so it could in fact be used in this particular case. – Nicholas Knight Mar 5 '11 at 6:49

You could use a mod_rewrite using a RewriteMap with a single value:

RewriteMap server txt:/path/to/file/map.txt
RewriteRule ^/(.*) http://${server:production}/$1 [P,L]

Then create /path/to/file/map.txt with this content

# To use a different server, change appserver.com 
# to e.g. maintenance.appserver.com

production appserver.com

As soon as mod_rewrite detects that you've changed this value it will automatically proxy the requests to the new server.

You can use one of several RewriteMap types with different performance impacts: database files, randomized text-file maps, even external programs -- in short, you can perform all kinds of arcane magic with them. Read all about it in the mod_rewrite docs and decide for yourself what would be the best option.

  • sweeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeet, many thanks – Fire Crow Oct 5 '09 at 20:17
  • this answers the question only because he was using mod_proxy when he didn't need it i have the same problem but i'm proxying an internal docker, so rewrite isn't an option – Ulises Layera Jan 11 '18 at 22:09

This should be possible using mod_rewrite.

Something like this:

RewriteEngine on
RewriteCond /some/path/dynamic-server-is-down !-f
RewriteRule ^/(.*) http://dyn:80/$1 [P]
RewriteCond /some/path/dynamic-server-is-down -f
RewriteRule ^/(.*) http://static:80/$1 [P]

Then just touch the dynamic-server-is-down file to switch over to the static server.

  • codehead's use of RewriteMap is a similar idea. Even more possibilities there using an external program. – freiheit Oct 5 '09 at 18:53

I don't think there's an easy way to do that. However, if you expect the proxy server to change why not proxy to a virtual IP or a DNS alias. That way if you need to switch out the server being proxied to, you can reassign the virtual IP or change the alias to point to the new server.


You might try "reload" rather than restart. Restart will stop and start the server, reload just reloads the configuration.

  • 1
    "graceful" is even better than reload since it doesn't close any active connections. – freiheit Oct 5 '09 at 18:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.