Use both Apache and Tomcat parallel
In a recent article I described how to configure a Tomcat web server to host also PHP projects. Now the question is: is it possible to host both, PHP and Java web projects on Tomcat and Apache? The answer is YES! Apache listens per default on port 80 and Tomcat listens to port 8080. On my recent article I configures Apache to redirect all http requests to Tomcat. For this I configured the following into http.conf:
ProxyPass / http://localhost:8080/
As you can see everything is passed from root requests to the root level, but for port 8080.
Motivation
The reason to why I want to redirect PHP to Apache and not to Tomcat is easy. I have an Facebook App that has to be avaliable for http:// and https://. For this is was not possible to configure a port forwarding that worked. Also it is easier to configure https:// for Apache as for Tomcat.
How can I do it?
If you want to make rules which program should be processed by Apache and which for Tomcat it is possible to explicitly say which program folder should be port forwarded and which not:
ProxyPass /Testapplikation ! ProxyPass / http://localhost:8080/
For this example, if you type www.mydomain.com/Testapplikation into your browser address field, then the request will not be forwarded to Tomcat like all other.
Summary
If you want to use both Tomcat and Apache there are two possible solutions:
- you can install Apache and then Tomcat and keep everything on default settings. With this, every request is sent to Apache (default port 80) and only requests which explicitly set port 8080 will be sent to Tomcat for example: www.mydomain.com:8080/Tomcatapplikation
- if you want to use both without the need of the port you can use Mod_Proxy. With this Tomcat is the standard web browser and with the solution I showed above you can explicitly stop the forwarding to Tomcat to special applications.
If you have answers feel free to write a post.