DekGenius.com
[ Team LiB ] Previous Section Next Section

Recipe 10.3 Forwarding Requests to Another Server

Problem

You want requests for particular URLs to be transparently forwarded to another server.

Solution

Use ProxyPass and ProxyPassReverse directives in your httpd.conf:

ProxyPass /other/ http://other.server.com/
ProxyPassReverse /other/ http://other.server.com/

Discussion

Use this recipe when you have a frontend server and one or more backend servers, inaccessible from the Internet, and you wish to serve content from them. In the example given, when a request is made for a URL starting with /other/, Apache makes a request for the URL http://other.server.com/, and returns the content obtained by the client. For example, a request for the URL /other/example.html results in a request for the URL http://other.server.com/example.html.

The ProxyPassReverse directive ensures that any header fields returned by the secondary server (which contain the name of the server, such as Location headers) will be rewritten to contain the URL that the end user will actually be using, ensuring that the redirect actually functions as desired.

Note that links within HTML documents on the secondary site should all be relative, rather than absolute, so that these links work for users using the content via the proxy server. In the recipe given, for example, a link to /index.html removes the /other/ portion of the URL, causing the request to no longer hit the proxied portion of the server.

Using this technique, you can have content for one web site actually served by multiple web server machines. This can be used as a means to traverse the border of your network, or it can be used as a load-sharing technique to lessen the burden on your primary web server.

See Also

    [ Team LiB ] Previous Section Next Section