tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From André Warnier ...@ice-sa.com>
Subject Re: Connecting Apache Tomcat to Apache
Date Wed, 28 Jan 2009 21:48:02 GMT
Mike Eller wrote:
> Hi,
> 
> I am new to Tomcat and trying to get it up and running.
> 
> I have an Apache server (2.2.3) running on CentOS 5.2.  I want to add
> the capabilities that tomcat brings, mainly JSP for now.
> I followed the connector tutorial/guide on the web site.  I have tomcat
> running and can access pages if I use the port number in the url.
> According to the guide, Apache should be handing .jsp requests over to
> tomcat automatically.  I have went through the guide twice...still no
> luck.
...
Ok, I'll bite, even if there are quite detailed instructions available 
here :
http://tomcat.apache.org/connectors-doc/generic_howto/quick.html

..and even if Gregor gave you the short answer before.

First, a bit of theory.

I) If you look at your Tomcat's conf/server.xml file, you will see that 
there are two types of <Connector> defined, one for HTTP, and one for 
AJP.  The HTTP one listens for requests to Tomcat, in the normal HTTP 
format and usually on port 8080 or 8180 or so.  That is the one you say 
you can access directly from the browser.
The other one listens for requests in a different format (AJP) and on a 
different port (usually 8009 by default).
For a Tomcat application (for example a JSP page), it does not matter 
through which of these channels the request comes in.  It will process 
the request, and respond to it.  Tomcat will then route the response 
back through the same <Connector> on which it came in.


II) From Apache, there are three ways to communicate with Tomcat :

1) via the Tomcat HTTP connector, using "normal" HTTP requests.  At the 
Apache level, that is done by using the mod_proxy module.
Basically, this is the same mechanism as the one used when Apache acts 
as a "proxy" for any other webserver. You have to tell Apache which 
requests it must process itself, and which requests it should forward to 
the back-end server for which it acts as a proxy. Apache will forward 
the request, receive the answer from the back-end server, and pass it 
through to the waiting browser.

2) via the Tomcat AJP connector, using the AJP format, but still at the 
Apache level using the mod_proxy module, this time with the addition of 
a helper mod_proxy_ajp module.  Apache will still receive the original 
request, decide if it has to go to the back-end Tomcat server, and if 
yes pass it on, but this time it passes it on through the mod_proxy_ajp 
module, which transforms the request format from pure HTTP into some 
different format called AJP.  Then this mod_proxy_ajp module forwards 
the request, not to the HTTP Connector of Tomcat, but to the AJP 
Connector of Tomcat.  Other than that, it is the same configuration as 
(1) above.

3) via the Apache add-on "mod_jk" module, also to the Tomcat AJP 
Connector.  That is presumably the one you are trying to use.
It differs of the above two methods, in that you are no longer using the 
standard "proxy" module of Apache, you are using a special dedicated 
handler, mod_jk.

There is a slight performance difference between the 3 above options, 
and quite a bit of difference in terms of configuration and 
capabilities.  But we'll leave that for another time.

III) Telling Apache which requests (which URLs) it needs to pass to 
Tomcat.
There again, there are 2 ways to indicate this to Apache :

1) through Apache configuration directives called "JkMount" and 
"JkUnMount".  For example, to tell Apache that all requests for URLs 
starting with "/examples" should go to Tomcat, you would use these two 
lines :
JkMount /examples worker1
JkMount /examples/* worker1

(where "worker1" is just a name that you will encounter again in the 
"workers.properties" file, see in IV below).

2) with a section like this (same basic effect, but more flexible):
<Location /examples>
   setHandler jakarta-servlet
</Location>

Now with either (1) or (2) Apache knows that if a request URL starts 
with "/examples", then it should pass it to the mod_jk module in order 
to generate a response.
That's basically all that Apache knows.

When the mod_jk module is given this request, it will try to pass it to 
Tomcat for processing, and wait for the answer.  When the answer comes 
back, mod_jk gives it to Apache, which sends it to your browser, et 
voila, you run Java servlet examples in Apache !

IV) configuring mod_jk

Of course, for mod_jk to know where Tomcat is, and how to pass it the 
request, it needs instructions.
That is the role of the "workers.properties" file.
Basically, this file contains parameters that tell mod_jk that the 
Tomcat that you called "worker1" above, is located at a certain host 
address (in your case probably "localhost") and at a certain port (the 
one referenced in the "port" attribute of the Tomcat AJP Connector in 
Tomcat's server.xml file, probably 8009).

Now go back to Gregor's instructions about where to find these various 
files and instructions.



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message