Apache2 mod_proxy /w multiple reverse proxies

apache-2.2mod-proxyreverse-proxy

If you access a file via a reverse proxy and the file is not found (returns 404), can apache2/mod_proxy automatically check for the file on another server by doing another reverse proxy?

workflow is like so:
1. request the file on the server doing the reverse proxy
2. server looks for the file on server A
3. file not found on server A, so it checks server B
4. file was found on server B, so it gets returned.

I already know other offerings can do this, but I was curious if mod_proxy can do this?

Best Answer

There is way, but not using 404, and to be honest it's a bad idea.

First, set maxattempts to a number bigger than 1. Set nofailover to Off.

Then in the backend that does not hold the object you want, you return a 503 when you want it to try the next one. (503 = HTTP_SERVICE_UNAVAILABLE)

This won't work in the real life though. Apache has no way of guessing what's a real 503 error, and what's a "try the other server" error. In other words, it will break the real 404 detection. There will be no way of issuing a 404 "page not found" error, since you'll always will return "service unavailable" errors to the users after apache gives up trying all servers.

Besides, the thing you're trying to do here is not a good idea, IMHO. You should configure proper mappings on your Apache Proxy, and assign servers based on the URLs of your requests.

http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#forwardreverse

Related Topic