I'm moving a big directory of images from an HTTP server to another and I cannot change any configuration.
I would like my user don't even suppose that a moving in progress. So I thought to add an Apache httpd server configured as reverse proxy in front of both the servers.
This reverse proxy when a resource is not found in the destination should try to get it in the origin server.
Is there any way to do this using mod_rewrite or some standard Apache httpd module?
The resources are not on the front-end server, but on two back-end servers.
To check for remote resources in RewriteCond you can use the following:
I never personally used it. But it works like testing for a file existence and the like.
You can then have a RewriteRule that proxies the request (the [P] option).
I have implemented a reverse proxy with Apache httpd 2.2, but it is not possible do it using only apache directives. So I had to use a simple PHP script in order to check remote url existence.
When a new request comes, it check the existence of current path on Server A and, if successfully found, it reverse proxy the request on same server. On the other hand, if the requested path is not found on Server A, it implements a rewrite rule reverse proxy on serverB.
I have used a
RewriteMap
withMapType
prg:
and a PHP script. There are the Apache directives:Here comes the interesting and tricky part. This is the
url_exists.php
script, executed by Apache. It is waiting on the standard input stream and write into standard output. This scripts return1
if the resource is found and readable, otherwise0
. Actually it is quite simple because it implements only an HTTP request using the HEAD method.