Configuring Apache to redirect to multiple HTTP services on the local machine

home | snippets | apache configuration

For a simple server, such as a living-room Internet server, it is often desirable to run multiple HTTP services on the one machine. In my case, the web server is Apache, and I want to different parts of my site (goverend by path) processed by different HTTP services (Apache, Tomcat, IIS).

For Apache 1.3.27, uncomment these lines:

AddModule mod_rewrite.c
AddModule mod_proxy.c
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule proxy_module modules/mod_proxy.so

Later, either within a virtual host entry or the main host entry, add your re-writing logic.

<IfModule mod_rewrite.c>
	RewriteEngine on
	RewriteLog "logs/rewrite_log"
	RewriteLogLevel 0
	RewriteRule ^/gallery(.*) http://drewnoakes.com:8080/gallery$1 [P]
	RewriteRule ^/aspx(.*)    http://drewnoakes.com:8090$1 [P, L]
</IfModule>

This redirects all traffic matching /gallery to a Tomcat web-app 'gallery', where Tomcat is running on port 8080. Similarly, any requests matching /aspx are redirected to IIS, which runs on port 8090.

With this setup, both Tomcat and Apache run on ports which are blocked by the firewall.