Wendy S said:
What URL pattern do you propose to configure so that this URL gets handed
off to Tomcat? If you put "/" then *every* request is going to go to
Tomcat and you might as well not have Apache.
Search the archives of tomcat-user for info on the "redirect problem". Last
time I researched it, the redirect was put in as part of a bug fix. There
were murmurings of making it configurable, but I don't know whether that
happened.
Actually, I was finally successful by using mod_rewrite, and no, only
servlet requests were redirected to Tomcat; Apache served *.gif,
*.css, and everything else I didn't explicitly map as a servlet in
JK2's workers2.properties config file. Also, even if every request
went to Tomcat it wouldn't be completely useless because you wouldn't
have to run Tomcat on port 80 as root; it is beyond the technical
capabilities of the Tomcat team to switch the UID of Tomcat to
non-root after grabbing port 80 but before serving any requests as
Apache does.
First, in Apache's httpd.conf file you need to make sure to load the
JK2 module *before* loading mod_rewrite:
....
LoadModule jk2_module modules/mod_jk2.so
LoadModule rewrite_module modules/mod_rewrite.so
....
If you don't do this then it won't work. I had to figure this out by
trial and error and it was very frustrating. These stupid people don't
know how to document anything.
Next, while still in httpd.conf set up the following mod_rewrite rule:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^/$ /index [PT]
</IfModule>
The [PT] is very important and if you don't include it then Apache
will look for a file named "index" and not find it. The [PT] (P)asses
(T)hrough the request to JK2.
Next, in JK2's workers2.properties config file you need to explicitly
set up each request URI you want Apache to pass through to Tomcat. For
example:
....
[uri:/index]
[uri:/login]
[uri:/logout]
....
Any pattern you don't set up here will won't be passed to Tomcat and
will be handled by Apache. So if you don't handle *.gif here then
Apache will handle it for you which is what you want.
Don't forget to set up <servlet-mapping>'s in your application's
web.xml. For example, if your index servlet's class is just Index,
then you'd do:
<servlet>
<servlet-name>Index</servlet-name>
<servlet-class>Index</servlet-class>
</servlet>
....
<servlet-mapping>
<servlet-name>Index<servlet-name>
<url-pattern>/index</url-pattern>
</servlet-mapping>
All the <servlet>s need to go before the <servlet-mapping>s.
Shutdown and startup Tomcat before starting up Apache. Or, if you do
leave Apache running, don't send any requests to Apache during
Tomcat's extremely long Java startup time because it leads "internal
server error" messages and you'll have to restart again.
Also, if you run Tomcat standalone and have set up a Context in the
server.xml file to be reloadable then it will be reloadable just fine
but if you use JK2 then suddenly reloading breaks and you get internal
server error messages. You need to restart Tomcat everytime you update
a servlet class. Not very nice for development, so you can't use this
setup while developing.
Finally, I observed random internal server error messages when running
JK2 which I can only attribute to bugginess. Additionally, while
cookies were enabled I observed sporadic unnecessary JSESSIONID
url-rewriting; url-rewriting has always worked perfectly with Tomcat
standalone: it's never used when cookies are enabled and always
automatically used when they aren't.
Because of this observed bugginess I decided to not use JK2. I tried
using mod_webapp but when I connected through mod_webapp my JNDI
connection pool datasource stopped working while it would work when I
connected to Tomcat directly. Doing google searches I saw that other
people have been reporting the same problem and getting no useful
replies.
Can these Tomcat people get anything right?
I'm going to be investigating either a professional servlet container
like weblogic or I'm going to write a custom servlet container that
implements only what I need. (I don't use filters, for instance.) Or,
I might switch to mod_c or something and write this thing in C/C++.
I'm really turned off to the whole Java/servlet experience right now.