Hey peeps!
I wanted to let ya'll know that I ended changing my setup quite a lot from the last configuration files that I posted. While the other one worked (kinda) it didn't do what I wanted it to, and I presume that any of you who were foolish enough to listen to me earlier are having the same trouble.
First a bit about my setup. I have two domains
www.foo.com and
www.bar.com. I want to be able to have tomcat serve anything that I explicitly want it to serve, but not everything. For example I want it to execute jsp files that are part of a webapp, not jsp files I may post in a tutorial.
I'm running Apache2.0.49 and Tomcat 5.0.18.
I'm assuming that have been able to build mod_jk.so. If you haven't I can recommend that you read this entire thread and glean the correct settings from there. It's what I did, and I then promptly forgot how I did it. Sorry.
First I shutdown tomcat and apache (which were working in standalone mode before I began)
Code: Select all
/etc/init.d/apache2 stop
/etc/init.d/tomcat stop
Next I set up my directories
Code: Select all
/var/www/foo/
/var/www/bar
chgrp -R apache /var/www/foo
chgrp -R apache /var/www/bar
Note: you will need to add the apache user to the tomcat group. Do this how you feel comfortable, I edited the /etc/groups file by hand. I also added tomcat to the apache group just in case, I doubt it's needed.
I moved mod_jk2.so and libjkjni.so into /etc/apache2/extramodules/
I edited /etc/apache2/conf/apache2.conf
Below the last LoadModule section I added
Code: Select all
###
### New Modules added by SBudda
###
LoadModule jk2_module /etc/apache2/extramodules/mod_jk2.so
I also uncommeted
Next I edited /etc/apache2/conf/vhosts/vhosts.conf
Code: Select all
################# Named VirtualHosts
NameVirtualHost 192.168.1.3
<VirtualHost 192.168.1.3>
ServerName www.foo.com
ServerAlias foo.com *.foo.com
DocumentRoot /var/www/foo
<Directory /var/www/foo>
<IfModule mod_access.c>
Order allow,deny
Allow from all
</IfModule>
</Directory>
</VirtualHost>
<VirtualHost 192.168.1.3>
ServerName www.bar.com
ServerAlias bar.com *.bar.com
DocumentRoot /var/www/bar
<Directory /var/www/bar>
<IfModule mod_access.c>
Order allow,deny
Allow from all
</IfModule>
</Directory>
</VirtualHost>
Where the IP address is the address for your server in your internal LAN.
Next I edited /opt/tomcat/conf/jk2.properties (you may have to create this file)
Code: Select all
# jk2.properties
# Set the desired handler list
handler.list=channelSocket,request
# UNIX Domain socket location
channelSocket.port=8009
# Dynamic library
serverRoot=/usr/local/apache2
apr.NativeSo=/etc/apache2/extramodules/libjkjni.so
Next I rewrote /opt/tomcat/conf/server.xml
Note that what I wanted to do, was place all of the webapps into a /var/www/[domain]/webapp/ directory, but I want to declare each webapp individually.
Code: Select all
<!-- Foo-Bar Server Configuration File -->
<Server port="8005" shutdown="SHUTDOWN" debug="0">
<!-- Define the Tomcat-Apache Service -->
<Service name="Tomcat-Apache">
<!-- Define a Coyote/JK2 AJP 1.3 Connector on port 8009 -->
<Connector className="org.apache.coyote.tomcat5.CoyoteConnector"
port="8009" minProcessors="5" maxProcessors="30"
enableLookups="true" redirectPort="8443" debug="0"
acceptCount="10" connectionTimeout="20000"
useURIValidationHack="false"
protocolHandlerClassName="org.apache.jk.server.JkCoyoteHandler" />
<!-- Define the top level container in our container hierarchy -->
<Engine name="Apache" defaultHost="www.foo.com" debug="0">
<!-- Global logger unless overridden at lower levels -->
<Logger className="org.apache.catalina.logger.FileLogger"
prefix="apache_log." suffix=".txt"
timestamp="true"/>
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="logs" prefix="localhost_access_log."
suffix=".txt" pattern="common" resolveHosts="false" />
<!-- Define foo.com virtual host -->
<Host name="www.foo.com" debug="0"
appBase="/var/www/foo/webapp"
unpackWARs="true" autoDeploy="true" >
<Alias>localhost</Alias>
<Alias>foo.com</Alias>
<Context path="/webapp/bob" docBase="bob" debug="0" />
<Context path="/webapp/isYourUncle" docBase="isYourUncle" debug="0" />
</Host>
<!--Define bar.com virtual host -->
<Host name="www.bar.com" debug="0"
appBase="/var/www/bar/webapp"
unpackWARs="true" autoDeploy="true" >
<Alias>bar .com</Alias>
<Context path="/webapp/rob" docBase="rob" debug="0" />
<Context path="/webapp/roy" docBase="roy" debug="0" />
</Host>
</Engine>
</Service>
</Server>
Then I edited /etc/apache2/conf/workers2.properties (you may have to create this file)
Code: Select all
# workers2.properties
[shm]
file=anonymous
[channel.socket:localhost:8009]
port=8009
host=127.0.0.1
#
# Define the worker
#
[ajp13:localhost:8009]
channel=channel.socket:localhost:8009
#
# Uri Mappings
#
[uri:www.foo.com/webapp/bob/*]
worker=ajp13:localhost:8009
[uri:www.foo.com/webapp/isYourUncle/*]
worker=ajp13:localhost:8009
###
[uri:www.bar.com/webapp/rob/*]
worker=ajp13:localhost:8009
[uri:www.bar.com/webapp/roy/*]
worker=ajp13:localhost:8009
I copied my .war files (or expanded webapps) into the proper locations in /var/www, and I made sure that tomcat could read them...
Code: Select all
chown -R tomcat:tomcat /var/www/[domain]/webapp/
Then I started up tomcat
Note: After you start tomcat, wait a few seconds before starting apache2. The author recommends singing Camp Town Races or Buffalo Gal.
"Won't you come out tonight, won't you come out tonight
Finally I started apache
That did it for me, every thing works quite nicely! My apologies if this doesn't work for you, or if you have other goals cause I probably won't be able to help you... but maybe this will get you on your way.
Thanks to all of the other posters, I couldn't have gotten it working without your great help!