I know there are lots of topics related to Apache HTTP Server + Tomcat, but I didn't find the solution to my problem yet, but it's for sure someone has already met a problem like mine.

I installed XAMPP for Windows 1.6.8, and then Tomcat 6.0.20 Add-On, because we would like to serve some PHP AND Java contents too.
It's OK, Tomcat is working with the default XAMPP settings on the address http://localhost:8080. (Here's the actual server.xml in "c:\xampp\tomcat\conf\", the workers.properties in "c:\xampp\tomcat\conf\jk\" and the mod_jk.conf file in "c:\xampp\tomcat\conf\auto\".)

But I would like to set the Apache HTTP Server the way that it would directly serve PHP contents OR for given domains on which we would serve Java contents, it would redirect queries to Tomcat (to serve Java contents). We would like to serve more PHP- and Java-sites on the same server.
For example:

  1. We have already reserved the domain example_page_1.hu, which is a PHP-based site, so Apache HTTP Server would deal with it. So when the user types example_page_1.hu in his/her browser, we would serve a PHP-based site.
  2. We have already reserved the domain example_page_2.hu too, which is a Java-based site, so Apache HTTP Server would redirect the query to Tomcat. So when the user types example_page_2.hu in his/her browser, we would serve a Java-based site.
  3. We have already reserved the domain example_page_3.hu, which is also a Java-based site, so Tomcat would deal with it.
  4. We have already reserved the domain example_page_4.hu, which is a PHP-based site, so Apache HTTP Server would deal with it again.
  5. etc...

What is the appropriate configuration for Apache HTTP Server (httpd.conf --> VirtualHost, etc.), and for Tomcat (server.xml, etc.) in XAMPP? I'm totally new in using Tomcat, so could you please write a step-by-step guide? (for example what I should write in my config files like according to the example)
I would be really grateful, because I just got the task to move some Java contents from a "pure" Tomcat server to our own server on which I installed XAMPP+Tomcat Add-On to serve PHP and Java contents too.
Thanks! :)


EDIT:

Assuming that we have registered example_page_1.hu domain (there's a real one working), the following is already working for the ROOT of Tomcat, so when the user types the http://example_page_1.hu address, he will see what I can see when typing localhost:8080, with the following lines in httpd.conf:

<VirtualHost *:80>
   ServerName example_page_1.hu
   ErrorLog c:/xampp/tomcat/logs/ajp.error.log
   CustomLog c:/xampp/tomcat/logs/ajp.log combined

   <Proxy *>
     AddDefaultCharset Off
     Order deny,allow
     Allow from all
   </Proxy>

   ProxyPass / ajp://localhost:8009/
   ProxyPassReverse / ajp://localhost:8009/
</VirtualHost> 

It's OK, but there's a problem.
When I rename ROOT directory to ROOT_BACKUP, I can reach it via the following URL: http://example_page_1.hu/ROOT_BACKUP. Than I copy the contents from the original server to ROOT directory, but it doesn't work, I get an 503 (subdirs like ROOT_BACKUP can still be reached).
The mentioned stuff is some kind of Vaadin application, so the ROOT directory of the original Tomcat server (in webapps dir) consists of these subdirs: META-INF, VAADIN, WEB-INF, and there's one file too: vaadin-6.6.2.jar .
It also has some kind of certification for https-connections, so <Connector> tag in server.xml has a keystoreFile attribute with the path of the keyfile.

What should I do with it to work? Currently I would like to make the first application work, doesn't matter that it's in the ROOT... After solving this problem, we could solve the rest... :)

link|improve this question

12% accept rate
feedback

2 Answers

You can use fastcgi to serve those PHP pages. AFAIK you can configure this on VirtualHost basis. I don't know about Tomcat, but I'm pretty sure it should be possible to configure this on VirtualHost level too.

I (again) need to admit that I don't know about Tomcat's protocol, but you may be able to this using mod_proxy. Since your Tomcat-server is running on :8080, you can proxy to that address from your :80 Apache-server =)!

link|improve this answer
to be honest, I don't really understand why you suggest that I should serve PHP pages with fastcgi when there's the already working Apache HTTP Server... I know that I can use VirtualHost settings to redirect stuffs to Tomcat, but the question was HOW to do it. I have tips and tries (see the edited post), but I'm curious about the real solution. But thanks. – Sk8erPeter Aug 15 '11 at 18:56
feedback
  1. Copy one more Tomcat into c:\xampp\, rename to tomcat8081. Open the server.xml and change <Connector port="8080" protocol="HTTP/1.1" to 8081 and <Connector port="8009" protocol="AJP/1.3" redirectPort="8444" /> to 8010.

  2. Open the c:\xampp\tomcat\conf\server.xml and change:

    <Engine name="Catalina" defaultHost="localhost">
    

    to:

    <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">
    

    and:

    <Host name="localhost"  appBase="webapps"
               unpackWARs="true" autoDeploy="true"
               xmlValidation="false" xmlNamespaceAware="false">
    

    to:

    <Host name="localhost"  appBase="webapps"
               unpackWARs="true" autoDeploy="true"
               xmlValidation="false" xmlNamespaceAware="false">
       <Context path="" docBase="app1" debug="0"/>
    
  3. Do the same for c:\xampp\tomcat8081\conf\server.xml but jvmRoute="tomcat2" and docBase="app2". (Assumming that you have app1.war file for the example2.hu and app2.war for the example3.hu)

  4. Change workers.properties to something like this:

    worker.list=tomcat1, tomcat2
    
    worker.tomcat1.port=8009
    worker.tomcat1.host=localhost
    worker.tomcat1.type=ajp13
    worker.tomcat1.lbfactor=1
    
    worker.tomcat2.port=8010
    worker.tomcat2.host=localhost
    worker.tomcat2.type=ajp13
    worker.tomcat2.lbfactor=1
    
  5. Create 2 virtualhosts for example2.hu and example3.hu like belows:

    <VirtualHost *:80>
        ServerName example2.hu
        JkMount  /* tomcat1
    </VirtualHost>
    
    <VirtualHost *:80>
        ServerName example3.hu
        JkMount  /* tomcat2
    </VirtualHost>
    
  6. Restart Apache, Tomcat and test.

link|improve this answer
Hi! Thanks for your long answer! But the problem is that I don't have any .war files. :( That's some kind of Vaadin application (vaadin.com), so the ROOT directory of the original Tomcat server (in webapps dir) consists of these subdirs: META-INF, VAADIN, WEB-INF, and there's one file too: vaadin-6.6.2.jar . Btw I copied these into "c:\xampp\tomcat\webapps\app1\". I made the modifications you suggested, but Apache didn't even start. After deleting the VirtualHost lines it does start, maybe it doesn't like the JkMount line...Btw where should the server know where tomcat2 is? – Sk8erPeter Aug 15 '11 at 18:22
One more problem: there are two workers.properties files after copying (in "c:\xampp\tomcat\conf\jk\" and in "c:\xampp\tomcat_8081\conf\jk\" [I rather put an underscore after tomcat in the directory name]), so which should I modify as you suggested? Now I modified both of them... There's one more thing I have to tell: I also tried what happens if I just have one Java application, so I copied the mentioned stuffs into the Tomcat's ROOT directory in webapps, but it also didn't work... (BUT the test page does work on the localhost:8080.) I edited my original post, please watch the modifications! – Sk8erPeter Aug 15 '11 at 18:29
For the first problem: what output you get when restarting Apache? And what does Apache error log say? For the second, you can edit any file you want but point to the right location with JkWorkersFile in mod_jk.conf. – quanta Aug 16 '11 at 4:11
Apache error message when starting the service was like the following: goo.gl/AFQEy. So nothing specific could be read. I think there was nothing interesting in Apache error log, which was related to the problem. mod_jk.conf is automatically generated by Tomcat when starting it. So does it mean I have to start as much Tomcat-instances as much domains I would like to serve my Java-contents with? It would be a bit interesting to me... like I don't have to start as much Apache HTTP Servers as much PHP-contents I would like to serve for specific domains... :S – Sk8erPeter Aug 16 '11 at 11:29
one more thing: when I use Proxy tag, ProxyPass and ProxyPassReverse as mentioned in my original post after editing it, it does work for the Java testpage I linked for a given domain name (like example_page_1.hu). Isn't it a possible solution for the rest of the domains? Or does this method cause any problems? – Sk8erPeter Aug 16 '11 at 11:34
feedback

Your Answer

 
or
required, but never shown

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