File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Tomcat and the fly likes mod_jk and Apache Virtual Hosts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "mod_jk and Apache Virtual Hosts" Watch "mod_jk and Apache Virtual Hosts" New topic
Author

mod_jk and Apache Virtual Hosts

Chris van de Paas
Greenhorn

Joined: Sep 11, 2011
Posts: 1


I have set up a virtual host in Apache, which is intended to host and execute all Servlets and JSPs which are located in this vhost directory.

(A snippet of my config-files is on to bottom of this post, because attachments doesn't work yet.)


This setup works fine, BUT the Servlets / JSPs are processed ONLY when they are stored and executed in Tomcat's "webapps" folder.
(When I move the Servlets and/or JSPs to the vhost-directory, I get an error; produced by Tomcat.)


So - WHAT CAN I do that my Servlets and JSPs are stored AND executed in my vhost directory?


Kind regards, Chris


P.S.: I've read a lot of documentations and tried out many different setups before I posted this thread!







Config Snippet:

###
# httpd.conf
###

# I've deleted all uncommented tags (#) AND those which seem to be unnecessary (for my setup)



#........

Listen 80

#........

Include conf/mod_jk/httpd-jk.conf

#........


NameVirtualHost *


<VirtualHost *>
      ServerName www.mydomain.com
      DocumentRoot /.../www
</VirtualHost>

#........

<VirtualHost *>
      ServerName servlettest.mydomain.com
      DocumentRoot /.../servlettest

      JKMount /* worker1
</VirtualHost>




###
# httpd-jk.conf
###

# I've deleted all uncommented tags (#)



LoadModule jk_module modules/mod_jk.so


<IfModule jk_module>

      JkWorkersFile conf/mod_jk/workers.properties

      JkLogFile logs/mod_jk.log

      JkLogLevel info

      JkShmFile logs/mod_jk.shm

      JkWatchdogInterval 60

</IfModule>


#END config snippet
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15657
    
  15

First you need to understand how Enterprise Java webapps are architected.

You cannot simply dump a bunch of files somewhere and expect them to run in Tomcat or for that matter, any other J2EE webapp server. A J2EE webapp is - according to the standard, a bundle of files with specific meanings and relationships, all zipped together in a JAR called a WAR file. Tomcat can deal with unzipped versions of this JAR format as well (called "exploded WARs"), but the actual j2EE standard only specifies them in zipped form.

As part of this standard, a web application context is defined. Since a J2EE can host many apps - even without virtual hosting - each webapp has a context path that's part of the URLS that get routed to that particular webapp. In fact, it's the context path that determines which app the URL is routed to.

Furthermore, to execute servlets, you have to map the servlet to a URL pattern as well, which is something you do by coding the mapping in the WEB-INF/web.xml file of the WAY. Very, very old Tomcat releases didn't require this, but it was a horrible security feature and J2EE is big on security.

You don't need to define your WAR - or its directories - to Apache httpd at all, however. Just set up an Apache virtual host and code the appropriate mod_jk or mod_proxy directives in that virtual host definition. Apache will then forward all the matching URLs to Tomcat and Tomcat can take care of the rest. As long as you've deployed your webapp correctly inside Tomcat.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: mod_jk and Apache Virtual Hosts
 
Similar Threads
tomcat 4.0.4 and apache-1.3.22 integration
apache (tomcat) not parsing XML file?
Apache 1.3 / Tomcat 4.0 Configuration Problem
Setting up 2 application using virtual host in apache
Apache SSL Module on Ubuntu