DekGenius.com
[ Team LiB ] Previous Section Next Section

Recipe 10.5 Proxying mod_perl Content to Another Server

Problem

You want to run a second HTTPD server for dynamically generated content and have Apache transparently map requests for this content to the other server.

Solution

First, install Apache, running on an alternate port, such as port 90, on which you will generate this dynamic content. Then, on your main server:

ProxyPass /dynamic/ http://localhost:90/
ProxyPassReverse /dynamic/ http://localhost:90/

Discussion

Most dynamic content generation techniques use a great deal more system resources than serving static content. This can slow down the process of serving static content from the same server, because child processes will be consumed with producing this dynamic content, and thus unable to serve the static files.

By giving the dynamic content its own dedicated server, you allow the static content to be served much more rapidly, and the dynamic content has a dedicated server. Each of the servers can have a smaller set of modules installed than they would otherwise require, because they will be performing a smaller subset of the functionality needed to do both tasks.

This technique can be used for a mod_perl server, a PHP server, or any other dynamic content method. Or you could reverse the technique and have, for example, a dedicated machine for serving image files using mod_mmap_static to serve the files very rapidly out of an in-memory cache.

In the example given, all URLs starting with /dynamic/ will be forwarded on to the other server, which will, presumably, handle only requests for dynamic content. URLs that do not match this URL, however, will fall through and be handled by the frontend server.

    [ Team LiB ] Previous Section Next Section