Recipe 10.3 Forwarding Requests to Another Server


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


Use ProxyPass and ProxyPassReverse directives in your httpd.conf:

ProxyPass /other/ ProxyPassReverse /other/


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, 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

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


Apache Cookbook
Apache Cookbook: Solutions and Examples for Apache Administrators
ISBN: 0596529945
EAN: 2147483647
Year: 2006
Pages: 215

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: