Integrating Tomcat with Apache Via the mod_jk Module
Pages: 1, 2
With the module library now compiled, we need to install the
module and instruct Apache how to load the mod_jk libraries. To do
so, we'll have to do a few tasks as the "superuser." (I hope you
paid attention to the warnings about using the superuser
account!)
First, copy our newly-created module to the directory that holds the other Apache module files:
sudo cp mod_jk.so /usr/libexec/httpd/
Second, we'll have to modify the configuration file that
controls the operation of the Apache Web Server,
httpd.conf. Use your favorite text editor (the author's
preference is the emacs text editor).
emacs /etc/httpd/httpd.conf
Add the following to the end of the httpd.conf file,
just a few simple instructions instructing Apache to load the
module.
# Add and load the mod_jk module
LoadModule jk_module libexec/httpd/mod_jk.so
AddModule mod_jk.c
We'll have to add some additional lines in a few minutes, but this is enough to instruct Apache to load the module upon startup.
Configuring mod_jk
Now that we have built and loaded mod_jk, we need to tell Apache
and Tomcat how to enable the communication. Fortunately, the Tomcat
developers already have part of the configuration set up, so we'll
just have to take advantage of that and set up some very simple
files.
Configuration of the Tomcat connector is done via "workers" that
will enable the connection. Change directory to the Tomcat
conf/ directory and create a new file (with your favorite
text editor) called workers.properties. In this example, we
will set up a simple worker -- please consult the Tomcat
documentation for further instructions and examples. Here is the
example properties file:
# Setup for Mac OS X
workers.tomcat_home=/usr/local/tomcat
workers.java_home=/System/Library/Frameworks/JavaVM.framework/Versions/1.3.1/Home
ps=/
worker.list=ajp12, ajp13
# Definition for Ajp13 worker
#
worker.ajp13.port=8009
worker.ajp13.host=127.0.0.1
worker.ajp12.type=ajp13
Apache will need to find this file to load the resources and
create the connection with the running version of Tomcat. To do
this, we'll have to edit the same http.conf file that we
edited earlier. This time, add the following lines to the end of
the file (adjust the paths to something appropriate for your Tomcat
installation):
JkWorkersFile /usr/local/tomcat/conf/jk/workers.properties
JkLogFile /usr/local/tomcat/logs/mod_jk.log JkLogLevel debug
Before continuing, we can test the configuration to see if everything has been set up correctly. First, restart Tomcat, then Apache. You can restart Apache through the "Web Sharing" option in the System Preferences, or by opening a command line and entering:
sudo apachectl restart
If everything has been installed correctly, the tail of the Tomcat logs/catalina.out file should read:
Starting service Tomcat-Standalone Apache Tomcat/4.0.4 Starting
service Tomcat-Apache Apache Tomcat/4.0.4
With this last step, Tomcat is now able to serve requests for
servlets and JSPs from the Apache Web Server. In order to define
how an external browser uses an application, we'll have to define a
"Virtual Host" in the httpd.conf file. Virtual host
configurations can be somewhat complicated, and often reflect how
you want users to refer to your application. For example purposes,
we'll define our virtual host to be the default "localhost," which
is by default recognized at the IP address 127.0.0.1. (For further
reading on creating virtual hosts in a real-world deployment
environment, consult the book Apache: The Definitive Guide.)
To enable the virtual host, first check that the ServerName is
set to the localhost "loopback" address. Alter the definition of
ServerName to read:
ServerName 127.0.0.1
(There is a bit of documentation in the httpd.conf file
about how the ServerName works, and the prerequisites for
defining server names.)
With the server name defined, we can define a simple virtual host that will serve as an entry to the "examples" application included with Tomcat. This virtual host can be added to the end of the file:
<VirtualHost 127.0.0.1> DocumentRoot
/usr/local/tomcat/webapps JkMount /*.jsp ajp12 JkMount
/examples/servlet/* ajp12 </VirtualHost>
|
Related articles Installing Tomcat on Mac OS X -- The Tomcat server is ideal for deploying Web applications and Web services. It's also a snap to install on Mac OS X. Here's how. Using Tomcat -- a series of articles on ONJava.com by James Goodwill that features introductory Web application development issues, Tomcat installation and configuration, deploying Web applications onto Tomcat, Struts, and much more. |
The only "trick" involved is using the JkMount
directive, which instructs the mod_jk module to use a worker
defined previously in the workers.properties file.
After defining the virtual host, restart Apache. The examples
should now be accessible at the addresses
http://localhost/examples/jsp/ and
http://localhost/examples/servlets/, respectively. Be sure
to follow the links to verify that Tomcat is answering requests. As
a second test, you may wish to check the access logs for both
Apache and Tomcat. The Apache server should be serving the requests
for the static front pages for the examples, while Tomcat registers
the access requests for the JSP and servlet applications. After
this final check, we've now enabled our Mac to serve Java-based
applications using the built in Apache Web Server!
Chad Thompson is a developer based in Des Moines, IA. His primary interests are creating Java and XML based software, development methodologies (esp. Extreme Programming), and a recent rabid fascination with Mac OS X.
Return to the Mac DevCenter.
-
Invalid DNS entry in workers.properties file
2006-01-23 23:21:35 ahelp [View]
-
What about OSX 10.3, Apache 2.0 and Tomcat 5
2005-02-03 13:07:20 davemar [View]
-
What about OSX 10.3, Apache 2.0 and Tomcat 5
2005-04-17 20:55:23 MDW [View]
-
Config problem
2004-03-16 18:01:11 mj_igx [View]
-
IP Problem
2004-02-24 21:46:57 tan_chonghuey [View]
-
Server 10.3.2
2004-02-11 13:55:00 kmpatrik [View]
-
what the heck?
2003-12-03 06:56:36 cj8n [View]
-
what the heck?
2003-12-03 11:58:57 anonymous2 [View]
-
How I installed Tomcat 4.1.27 on Mac OS X Server 10.2.8 (X-Serve)
2003-10-24 12:17:48 anonymous2 [View]
-
WARNING: The contents are a little "old"
2003-08-24 09:44:04 cothomps [View]
-
WARNING: The contents are a little "old"
2004-11-21 13:44:34 lbois [View]
-
Please update
2003-03-18 13:51:05 anonymous2 [View]
-
Excellent work
2003-03-05 14:39:01 anonymous2 [View]
-
Integrating with OS X Server 10.2 Apache
2003-01-31 04:39:00 anonymous2 [View]
-
apxs build error (_regerror)
2002-12-19 03:35:38 rakella [View]
-
Fixes that make it work
2002-12-18 23:31:01 potel [View]
-
Fixes that make it work *sortof*
2003-04-24 22:13:32 anonymous2 [View]
-
Fixes that make it work
2002-12-24 21:28:41 spiffysj [View]
-
Typo
2002-12-04 11:48:30 anonymous2 [View]
-
This does not work
2002-10-31 17:39:32 anonymous2 [View]
-
mod_jk doesn't seem to be processing *.jsp pages
2002-10-22 09:24:30 anonymous2 [View]
-
Problems problems...
2002-10-22 08:01:42 anonymous2 [View]
-
these directions don't work
2002-10-01 23:47:03 anonymous2 [View]
-
great job
2002-09-19 16:37:38 anonymous2 [View]
-
Apple Laptop Keyboards Unsuitable for Unix Users
2002-09-18 02:23:02 anonymous2 [View]
-
Apple Laptop Keyboards Unsuitable for Unix Users
2003-09-28 13:20:55 anonymous2 [View]
-
Apple Laptop Keyboards Unsuitable for Unix Users
2003-07-21 23:08:21 anonymous2 [View]
-
Apple Laptop Keyboards Unsuitable for Unix Users
2003-07-13 14:36:13 anonymous2 [View]
-
Apple Laptop Keyboards Unsuitable for Unix Users
2002-11-21 23:57:39 anonymous2 [View]
-
"did not found a worker" Error...
2002-09-07 10:49:05 chan [View]
-
"did not found a worker" Error...
2004-04-21 18:48:10 srw [View]
-
"did not found a worker" Error...
2003-04-21 17:45:31 anonymous2 [View]
-
"did not found a worker" Error...
2003-07-23 08:10:10 anonymous2 [View]
-
"did not found a worker" Error...
2003-03-02 20:06:31 dberg [View]
-
"did not found a worker" Error...
2003-02-05 16:36:56 anonymous2 [View]
-
"did not found a worker" Error...
2006-01-27 04:30:56 baegsi [View]
-
whats the difference - mod_jk & mod_webapp
2002-08-31 22:49:24 mothcity [View]
-
whats the difference - mod_jk & mod_webapp
2002-09-03 19:52:26 cothomps [View]
-
apxs error when building mod_jk
2002-08-23 11:56:35 bmwood [View]
-
apxs error when building mod_jk
2002-08-26 20:48:58 cothomps [View]
-
Help: Finding the 'Headers' directory
2002-08-21 18:48:46 cothomps [View]
-
Help: Finding the 'Headers' directory
2002-08-22 01:55:35 jdicastro@austin.rr.com [View]
-
Help: Finding the 'Headers' directory
2002-08-22 06:42:43 cothomps [View]
-
Need Help
2002-08-21 18:12:50 jdicastro@austin.rr.com [View]
-
Nice work!
2002-08-21 00:17:31 donncha [View]

