How do I connect Apache to Tomcat using a proxy?
Author: Deron Eriksson
Description: This tutorial describes how to connect the Apache Web Server to Tomcat using a proxy.
Tutorial created using: Windows XP || JDK 1.5.0_09 || Eclipse Web Tools Platform 1.5.4 || Tomcat 5.5.20 || Apache HTTP Server 2.2.4
(Continued from page 1)
LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_http_module modules/mod_proxy_http.so
In my httpd.conf file, I add ProxyPass and ProxyPassReverse entries. In the example below, requests to Apache's /tomcat-demo-proxy path get mapped to Tomcat's port 8082 connector running on the same machine, with the tomcat-demo project specified as the project that we get mapped to.
ProxyPass /tomcat-demo-proxy http://localhost:8082/tomcat-demo ProxyPassReverse /tomcat-demo-proxy http://localhost:8082/tomcat-demo
If you'd like to, you can check and make sure the syntax of httpd.conf is correct using the -t switch on httpd.exe:
C:\Apache2.2.4\bin>httpd.exe -t Syntax OK C:\Apache2.2.4\bin>
Next, I'll stop and start Apache. After that, I'll hit http://localhost/tomcat-demo-proxy/test in a browser window.
As you can see, the request to Apache's /tomcat-demo-proxy/test path gets mapped to http://localhost:8082/tomcat-demo/test, which is exactly the behavior we were hoping for. The request to Apache gets sent to TomcatSW. Tomcat processes the request and returns the response, which we see in the browser window.