Tomcat configuration under OS X 10.2 server


If you're running OS X server, you've probably noticed that certain things (basic file and mail service, basic web service, authentication) work very easily using the built-in user interface.

However, if you've gone beyond these basic requirements, the nice Apple UI breaks down a bit. I've been toiling for the last few months to figure out which things can be touched and which can't. Here's my latest info about Tomcat and Apache under OS X

10.2 includes Tomcat, a powerful JSP/Servlet container that is part of the Apache distribution. The version included by Apple currently uses mod_jserv (the penultimate method for connecting Apache to Tomcat).

Basically, Tomcat runs on port 9007 (up from the default 8007) and Apache will talk to it over this port when it is instructed to.

Instructions for Tomcat's operation are in /Library/Tomcat/conf. The most important file is server.xml, which contains the instructions to be followed for every URL that comes through port 9007 from the Apache server. This file maps these requests to objects in the /Library/Tomcat/webapps directory (or other directories as specified in the server.xml file.

The Apache configuration is located in /private/etc/httpd. When using Apache under OS X, the files are a little more complex than most Apache configurations. The main file is httpd_macosxserver.conf, which contains the include statements for the other files, including tomcat.conf.

Tomcat.conf is used in conjunction with server.xml to map incoming requests from the Apache server into the tomcat instance. Based on the configuration files from Apple, and the additional information from Apache.org here are some hints to adding your own special lines to the tomcat.conf file in order to do what you need:

The following lines are unnecessary and can be removed unless you want to keep the existing JSP/Servlet examples available (probably not a good idea in a production environment, as they show information about your installation):

	ApJServMount /examples /root

The following line causes the webmail code to run. If you aren't using the JSP/servlet based webmail, then you should remove these as well:

	ApJServMount /WebMail/servlet /WebMail

That will leave you with the default line that maps all incoming top-level items to Tomcat:

	ApJServMount default /root

When adding your own JSPs and Servlets, you'll probably want to add a line of the form:

	ApJServMount _external_ [_protocol_://][_hostname_][:_port_]

where:

Item Meaning
external the external portion of the URL to match. So, if you put /bin here, then URLs of the form http://localhost/bin/foo will get passed to Tomcat as base/foo
protocol This needs to be ajpv12: if present
hostname The hostname of the Tomcat server. This can be left off if your Tomcat instance is on the same machine
port The port to connect to. Unnecessary if the default of 9007 is sufficient
base The base portion to send to Tomcat (see external above)

If you need more complex configurations, you can set up multiple Tomcat JVMs by using separate Tomcat instances running on different ports. These can be directed by using the port element above so that they are completely independent.

Finally, by placing the ApJServMount directive inside of a VirtualHost directive, you can differentiate based on the vhost.