Recipe 11.12 Sharing Load Between Servers Using mod_proxy
Problem
You want to have a certain subset of your web site served from
another machine, in order to share the
load of the site.
Solution
Use ProxyPass and
ProxyPassReverse to have Apache fetch the content
from another server:
ProxyPass /other/ http://other.server.com/
ProxyPassReverse /other/ http://other.server.com/
Discussion
These directives will cause requests to URLs starting with
/other/ to be forwarded to the server
other.server.com, with the path
information preserved. That is to say, a request for http://www.server.com/other/something.html
will be translated into a request for http://other.server.com/something.html.
Content obtained from this other server will be returned to the
client, which will be unable to determine that any such technique was
employed. The
ProxyPassReverse directive ensures that any redirect
headers sent from the backend server (in this case, other.server.com) will be modified so that
they appear to come from the main server.
This method is often used to have the dynamic portion of the site
served by a server running mod_perl—often
even on the same machine, but on a different port—while the
static portions of the site are served from the main server, which
can be lighter weight, and so run faster.
Note that URLs contained within documents are not rewritten as they
pass through the proxy, and links within documents should be
relative, rather than absolute, so that they work correctly.
See Also
|