2

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.

3

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.

  • Is there any sort of dummies guide to do this, I've been trying to do what you said for the past 2 hours or so with no luck, and I'm ready to kill myself. The guides aren't dumbed down enough for me I think, haha. I was running straight from the Tomcat server previously on port 80, but now I just want to redirect through apache to the tomcat server. – Conner Stephen McCabe Nov 8 '13 at 20:18
  • Sorry, I don't know any guide. Perhaps you can describe where you're stuck. First Tomcat should work when accessed directly on the new port. Then Apache should work on port 80. Test without redirecting first. Then enable the proxy. If you get an internal server error try to find the matching log entry – Michael Suelmann Nov 8 '13 at 21:38
  • Another simple example: gerrydevstory.com/2013/06/29/tomcat-apache-reverse-proxy – Michael Suelmann Nov 8 '13 at 21:43
  • I just tried the simple example you gave, with Tomcat running on port :8080 and this is the error I get when I type the DNS in from the server: ~"Service Temporarily Unavailable The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later. Apache/2.2.15 (CentOS) Server at www.mydns.co.uk Port 80" – Conner Stephen McCabe Nov 8 '13 at 22:15
  • Is www.mydns.co.uk:8080 working? Can you get the apache error logs? – Michael Suelmann Nov 8 '13 at 22:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.