logo

Weblog

Configuring mod_jk on Snow Leopard

A few months ago I wrote about building mod_jk for Mac Leopard. I was glad to learn last weekend that my notes were still correct while I build a recent version of mod_jk for Mac Snow Leopard. This post is about how I configured mod_jk to make the Apache webserver and Tomcat work together.

Mon 25 Jan 2010 / André / 2 comments

I installed Tomcat by copying the complete contents of the downloaded 'apache-tomcat-6.0.20.tar.gz' to the directory '/Library/Tomcat', thus effectively installing it in this directory. I've followed http://wiki.apache.org/tomcat/TomcatOnMacOS to make it automatically startup on starting my Mac. Reason why I usually use the script configured in StartupItems to restart Tomcat, allthough it can still be started with:

/Library/Tomcat/bin/startup.sh

And still stopped with 'shutdown.sh' is in that same directory.

The main link between Tomcat and Apache is the 'workers.properties' file. I usually create one in Tomcats config directory - in this setup '/Library/Tomcat/conf/workers.properties' - and never touch it again.

# from workers.properties.minimal
# provides minimal jk configuration properties needed to connect to Tomcat.
# The workers that jk should create and work with
worker.list=ajp13w
worker.maintain=60

# Defining a worker named ajp13w and of type ajp13
worker.ajp13w.type=ajp13
worker.ajp13w.host=localhost
worker.ajp13w.port=8009
worker.ajp13w.socket_keepalive=1
retries=3

This example ports the localhost webapp 'ROOT' to Apache. But other contexts can be configured in Tomcat, for example in 'server.xml', in a similar way.

<Host name="localhost" 
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Alias>www.toly.net</Alias>

<Context path="" docBase="/Users/Shared/webapps/ROOT"
debug="0" />
</Host>

The rest of mod_jk is configured in a file included in httpd.conf. Apple sometimes changes or overwrites configuration files when you update your machine so I configured most of mod_jk outside of it. I just made a link between both applications in a file '/private/etc/apache2/mod_jk.conf'. Note, that to change 'httpd.conf' and save 'mod_jk.conf' next to it you need to be root or use 'sudo'.

Include /private/etc/apache2/mod_jk.conf

It first includes the module, and contains the configuration for mod_jk: its log file, path to workers.properties etc.

# <IfModule !mod_jk.c>
LoadModule jk_module  /usr/libexec/apache2/mod_jk.so
# </IfModule>

# Configure workers.properties, logging to Tomcat's logdir
JkWorkersFile /Library/Tomcat/conf/workers.properties
JkLogFile /Library/Tomcat/logs/mod_jk.log
JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "

The virtual hosts that run in Tomcat.

NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot /Users/Shared/webapps/ROOT
ServerName www.toly.net

<Directory "/Users/Shared/webapps/ROOT">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
# handle all urls with tomcat
JkMount /* ajp13w

# apache handles certain static links
JkUnMount /*.css ajp13w
JkUnMount /*.ico ajp13w
JkUnMount /*.js ajp13w
JkUnMount /*.html ajp13w
JkUnMount /*.png ajp13w
JkUnMount /*.txt ajp13w
</VirtualHost>

The above example describes the ROOT webapp but other virtual hosts are similar. Notice that in this setup Tomcat will handle all url's. It states specifically all file extensions you want the Apache to handle. You want this when you create 'nice' links or SEO links for your content.
This a bit easier example is a virtual host that includes just a few url's of a Tomcat webapp 'test', only jsp files and servlets.

<VirtualHost *:80>
DocumentRoot /Users/Shared/webapps/test
ServerName demo.toly.net

JkMount /*.jsp ajp13w
JKMount /servlet/* ajp13w
</VirtualHost>

That's it. Test whether you configured Apache correctly by typing:

sudo apachectl configtest

Which should return 'Syntax OK'. If OK restart it.

sudo apachectl restart

Visit it to check.

2 comments | leave a comment

Your comment





* = Required.
Email addresses will never be published.
HTML is not possible, although a bit of Wiki syntax - like *bold* f.e. - is supported. You can make links when they are easily recognized as urls, f.e. www.toly.nl or http://tomcat.apache.org.
Off-topic or inappropriate comments will be deleted.

Thanks for your two articles. Those helped me a lot so far. Unfortunately I am not sure if it all works SO well on Snow Leopard.

There is no -arch 64bit compiling option anymore with the Snow Leopard XCode, right? I am saying that because I found none.

Second I set all this up a few days ago and still try to get it running, but I am always having one major problem:
Though mod_jk correctly loads all the JkMounts and unmounts for every URL on startup it complains (debug log) that there would not be any mapping defined for any URL I come up with. That is strange, because the configuration works on Linux and Windows systems. I downloaded a newer mod version though (1.2.30), so it could be a problem with the default 64bit compiler or with the newer version.

di 30 maart 2010 / Stefan Schubert

I'm not sure what you mean with the debug messages you get, but these may be related to your virtual host setup. In stead of using the JkUnmount directive you may test with using only the JkMount directive from the second virtual host example. When this works - and Apache serves all 'normal' files correctly - then you can be quite sure that you're Apache setup is correct. Next you could try excluding stuff from Tomcat and assigning these to Apache, like in the first virtual host example.

And yes, I believe you're remark about compiling mod_jk is correct, see the 'Building mod_jk...' post. Thanks.

ma 19 april 2010 / André → http://www.toly.nl

RSS feed

Tweet this article

geschiedenis

Dit is de zoveelste incarnatie van mijn website wie nieuwsgierig is kan de

oudere 'recente' wijzigingen bekijken.

En ik heb hier een pagina waarop ik nieuwe en oudere versies van my_editors verzamel.