| Tomcat 5 on Linux Step-By-Step | ||
|---|---|---|
| <<< Previous | Next >>> | |
|
This solution was developed with help from Trevor Butler. |
I have found that for certain versions of Linux, the deployment method I described for Apache-Tomcat integration with mod_jk2 may not work. Specifically, entries in the configuration file workers2.properties that map web application contexts on Tomcat may not work. I have noticed this anomaly when the components described below are used:
Table A-1. Potentially Problematic Combination Of Components
| Linux distribution | Mandrake 9.2 |
| Apache version | Mandrake's Advanced Extranet Server |
| mod_jk2 | JPackage mod_jk2 RPM package |
You get "404 Errors", even though you followed all the instructions in this document. When you look inside the Apache error logs, you find that requests are not getting passed to Tomcat, and Apache is instead trying to find the requested documents under its own DocumentRoot.
This problem looks like there is something wrong with mod_jk2. But if you try to access the status page, that is, using a browser to go to http://domain.com/jkstatus/, you get a full normal listing of the web applications currently deployed on Tomcat.
Another symptom of this problem is, you find that you need to explicitly declare each and every servlet and JSP file deployed in every context, in order to make them accessible, and to avoid the 404 errors.
The 404 errors are occurring because Apache seems to be ignoring wildcard specifications of contexts in workers2.properties. For example, if, in workers2.properties, you specified a context called MyFirst this way:
[uri:/MyFirst/*] |
You would find that trying to call the HelloWorld servlet is futile, and would give you a 404 error "Page not found". You could even try to call the index.jsp file specified in my document, or any other page, and it would return you a 404 error.
One solution around this is to specify each and every resource in the web application context. For example, for the HelloWorld servlet and index.jsp, you would need 2 URI mappings in workers2.properties, not just one.
[uri:/MyFirst/HelloWorld] [uri:/MyFirst/index.jsp] |
If you have a lot of servlets, JSPs, HTML pages, etc, this approach may be unfeasible. So, how do you use wildcards in this situation?
As it turns out, specifying your context in workers2.properties is not the only way to tell Apache to route web application context requests to Tomcat. The web application context can be specified within Apache's own configuration file. If you are using Mandrake's Advanced Extranet Server, that file would be /etc/httpd2/conf/httpd2.conf. If you use this approach, you may need to delete the URI contexts in workers2.properties.
I will use the example developed earlier in this tutorial. Suppose I have a HelloWorld servlet and an index.jsp file in the context called MyFirst. I will assume that you either built the mod_jk2.so and jkjni.so libraries successfully, or that you downloaded and have already successfully installed the mod_jk2 RPM package from JPackage.org.
To specify the MyFirst web application context to Apache, we append the following lines to the bottom of /etc/httpd2/conf/httpd2.conf :
# URI definitions <Location "/MyFirst/*"> JkUriSet worker ajp13 </Location> |
In some cases, you may need to enclose the context definitions inside IfModule, like so:
<IfModule mod_jk2.c> # URI definitions <Location "/MyFirst/*"> JkUriSet worker ajp13 </Location> </IfModule> |
Notice that this specifies a wildcard. This means that a browser that requests anything from http://domain.com/MyFirst/, will automatically have his request routed by Apache to Tomcat.
This solved the problem for me. If you know of anything else that may help, or if you would like to expand on my solution, feel free to email me !
| <<< Previous | Home | Next >>> |
| References and Useful Links | About the changes in web application deployment section |