Cory Foy

Sunday, May 08, 2005

Getting Tomcat and Apache running on Gentoo - Day 1

(Edit 3/6/2006: This is wrong, in that it still uses mod_jk2. This is not a how-to for mod_jk. Rjae Easton has a good post on getting mod_jk working that you should head over to if that's what you need. - Cory)

I don't really anticipate this taking that long, but figured I would document it out since I can't
find much documentation on this.

So the basic premise is that I have a Gentoo Linux box that I am hosting some sites on. I want to get Tomcat up and running so I can do some dynamic content with it. I already have Apache running, which I installed by doing the very difficult:

emerge apache2

I also had to do some config changes because I am running virtual hosts. I made sure that all this was fat and happy (which it was), so Apache is good.

Next I installed Tomcat. This also was just:

emerge tomcat

which hummed along quite nicely and plunked it on there. Doing a netstat -a showed me that it was running and listening, and browsing to localhost:8080 showed me the nice Tomcat install page.

Now, the final step is to get Apache to send my jsp's to Tomcat for processing. Much of the documentation I found revolved around mod_jk2 which has been deprecated for mod_jk. Of course, nobody really talks about mod_jk (which is why you are reading this!).

I started with a document called HOWTO: Apache2 and Tomcat5 from the Gentoo Wiki. The big difference was in mod_jk, which I built from source using the directions from this article on something called SnipSnap. My workers.conf was nearly identical to the workers.properties listed in the HOWTO article. For the apache2.conf, I moved it over to my vhosts/vhosts.conf file, which looks basically like:


################# Named VirtualHosts
NameVirtualHost *:80

LoadModule jk2_module extramodules/mod_jk2.so
JkSet config.file /etc/apache2/conf/workers2.conf

<VirtualHost *:80>
ServerName www.mysite1.com
ServerAlias mysite1.com *.mysite1.com
DocumentRoot /var/www/localhost/htdocs
<Location /*.jsp>
JkUriSet worker ajp13:localhost:8009
</Location>
</VirtualHost>

<VirtualHost *:80>
ServerName www.mysite2.com
ServerAlias mysite2.com *.mysite2.com
DocumentRoot /var/www/mysite2/htdocs
<Directory /var/www/mysite2/htdocs>
Order Allow,Deny
Allow from all
</Directory>
</VirtualHost>


At that's where I'm at. Both of my sites are still up, and sending a request to mysite1.com/test.jsp (a simple jsp) appears to do something, but it isn't quite working yet. Right now the page just sits there and spins, but I don't see anything funky in the server logs to help track it down. I'll try some more tomorrow.





UPDATE: So it turns out that the only thing I had wrong was my workers2.conf file. I had:


[channel.socket:localhost:8009]
port=8009
host=mysite1.com
type=ajp13


which was resolving the site name to the public IP address, which, of course, is firewalled and had port 8009 blocked. Changing it to:


[channel.socket:localhost:8009]
port=8009
host=localhost
type=ajp13


fixed it, and all is well with the site! Yea, no day 2 necessary!

5 Comments:

  • You are aware that site built mod_jk2 connector not a mod_jk connector. So going on about it being depreciated was fruitless. You are still using a mod_jk2 connector.

    By Anonymous Anonymous, at 12:35 AM  

  • No, I didn't realize that. I don't know why not, looking at it makes it very obvious. I'll take a look at it and see if I can switch it out for mod_jk. Thanks for the comment.

    By Blogger Cory Foy, at 1:28 PM  

  • I just added the following to /etc/portage/package.keywords

    www-apache/mod_jk ~x86
    net-www/apache ~x86
    dev-libs/apr ~x86
    net-www/gentoo-webroot-default ~x86
    dev-libs/apr-util ~x86

    then emerge -auvtDN mod_jk

    Presto!

    I found examining your config files every helpful. Thank you!

    By Anonymous dustfinger, at 4:51 PM  

  • these instructions leave you with mod_jk2 (look closely). i've posted proper instructions.

    By Blogger Rjae Easton, at 6:25 PM  

  • thanks for this note; i'll look forward to cross-pollinating in the future.

    By Blogger Rjae Easton, at 9:10 AM  

Post a Comment

Links to this post:

Create a Link

<< Home