Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I need to host two sites with Tomcat. This is what is in my Apache conf:

<VirtualHost *:80>
    ServerAdmin suporte@project.com
    DocumentRoot /root/tomcat/webapps/PROJECT
    ServerName www.project.com
</VirtualHost>    

To access the site, I can access only by the www.project.com/project. I can't access the index, for example: www.project.com

And what for the case when I want host another site ?

My idea:

<VirtualHost *:80>
    ServerAdmin suporte@project1.com
    DocumentRoot /root/tomcat/webapps/PROJECT1
    ServerName www.project1.com
</VirtualHost>    

But I've had no success.

How would I solve this?

share|improve this question

1 Answer 1

Using Apache and Tomcat together, delivering JAVA 'files' (servlets, jsp, etc.) doesn't work the way you sketched up. The way you did it there, you can only access the files and they are delivered depending on their mime type.

As a first step you should read up on reverse proxying and in your case the modules mod_proxy_http and or mod_proxy_ajp. I don't know what experience level you got, so I simply write up some lines you should adapt:

LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_ajp_module /usr/lib/apache2/modules/mod_proxy_ajp.so
<IfModule mod_proxy_ajp.c>
   <Location />
      ProxyPass ajp://127.0.0.1:8009/PROJECT
      ProxyPassReverse ajp://127.0.0.1:8009/PROJECT
   </Location>
</IfModule>

In a standard Linux environment you can install those modules with your package provider and enable them with a2enmod mod_proxy_ajp. This should also install mod_proxy as dependency. In that case you drop the LoadModule directives mentioned above.

The <Location /> directive is what handles all requests directed to your domain. So www.project.com delivers the index. There are some more considerations (security when using mod_proxy) and some such, but it should point you in the right direction.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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