Running Apache with Tomcat

apache-httpdjavatomcat

I was wondering if it's possible to run a Tomcat server within Apache whilst also running PHP servers under other virtual host instances? And if so, how is this done?

Basically, I'm trying to run an Apache server that redirects to different applications based on the DNS address used. For example:

www.javaapp.com -> Sends the Java application to the clients browser

and

www.phpapp.com -> Sends a PHP application to the clients browser

And I was also wondering if there's a way of adding a third application in RoR as well, and whether Apache can serve Rails or not?

I am currently using Tomcat for my JSP application, I know this can be integrated with Apache, but I wasn't sure if it could be done alongside applications written in other languages. As I know that Apache is able to redirect to virtual hosts based on the DNS address entered, which I thought was pretty cool and would really help me to host multiple applications on my box that I'm writing.

Best Answer

You can proxy the requests from Apache to Tomcat as described in http://tomcat.apache.org/tomcat-8.0-doc/proxy-howto.html. Basically you need something like this in your apache config:

ProxyPass         /myapp  http://localhost:8081/myapp
ProxyPassReverse  /myapp  http://localhost:8081/myapp

The same method should work too with Rails as long as you access your applications with a unique prefix like /myapp above.

If you want to proxy the whole virtual server (e.g. ProxyPass / http://localhost:8081/myapp), then the information in http://www.humboldt.co.uk/2009/02/the-mystery-of-proxypassreverse.html might be useful to keep redirects working.

Related Question