Scale to any number of web application servers with RewriteMap
As we saw in the
previous hack, it is possible to transparently serve content from any
arbitrary web server using mod_proxy and
mod_rewrite. Rather than using an external
[R], the proxy target
[P] makes the content appear to come from the
server from which the client originally requested content, without
changing the URL line in the client browser. As we saw earlier, one
application of this technique is to spread the load of serving pages
across two machines, making it possible to serve many more hits than
a single machine can handle.
But what if you need to serve even more traffic, to the point that a single application server is no longer sufficient? We need a mechanism that will allow the proxy servers to choose from an available pool of application servers, preferably in a way that we can direct more hits at more capable servers. The RewriteMap directive gives us this functionality.
Here's an example of how to specify a RewriteMap:
RewriteMap server rnd:/usr/local/apache/conf/servers.map
The RewriteMap line just defines a map called server, physically bound to the servers.map file in the conf/ directory. The rnd: makes this a randomized plain text map.
The format of the servers.map file is very straightforward:
The left-hand side is an arbitrary variable name that we can use just about anywhere in our configuration file, as ...