📄 apache + tomcat howto - windows 2000 pro-xp pro.htm
字号:
Word!! Use Notepad or another editor. Scroll down to where you see a bunch of
lines that say "LoadModule". At the end of this list, add a line that says:
<P>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR bgColor=#cccccc>
<TD><CODE>LoadModule jk_module modules/mod_jk-2.0.43.dll</CODE>
</TD></TR></TBODY></TABLE>
<P>Save the file you just edited to the APACHE_HOME\conf directory, and before
going any further, verify that you have things setup correctly. Open a command
prompt window by clicking Start->Run and typing <B>cmd</B> and clicking OK.
At the prompt, type <B>c:\apache\Apache2\bin\Apache.exe -t</B> and hit return.
You should see a message that says "Syntax OK". If you don't see this message,
go back to Step 1 and review any changes you have made to determine the error.
Note that using "-t" on the command line WILL NOT start the Apache service, it
just checks the changes that you made to httpd.conf for any errors.
<P>5. Edit Tomcat's configuration. First, make a copy of
c:\tomcat\tomcat-4-1-18\conf\server.xml. Now edit
c:\tomcat\tomcat-4-1-18\conf\server.xml. Look for a line that says
<P>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR bgColor=#cccccc>
<TD><CODE><Server port="8005" shutdown="SHUTDOWN" debug="0"></CODE>
</TD></TR></TBODY></TABLE>
<P>Just below that line, add the following:
<P>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR bgColor=#cccccc>
<TD><CODE><Listener
className="org.apache.ajp.tomcat4.config.ApacheConfig"
modJk="c:/apache/Apache2/modules/mod_jk-2.0.43.dll" /></CODE>
</TD></TR></TBODY></TABLE>
<P>Now look for a line that says
<P>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR bgColor=#cccccc>
<TD><CODE><Host name="localhost" debug="0" appBase="webapps"
unpackWARs="true" autoDeploy="true"></CODE> </TD></TR></TBODY></TABLE>
<P>Just below that line, add the following:
<P>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR bgColor=#cccccc>
<TD><CODE><Listener
className="org.apache.ajp.tomcat4.config.ApacheConfig" append="true"
forwardAll="false" modJk="c:/apache/Apache2/modules/mod_jk-2.0.43.dll"
/></CODE> </TD></TR></TBODY></TABLE>(note that this line, while similar to
the first one, is different)
<P>Save the changes you made to server.xml. Restart the Tomcat service. Wait a
few seconds, and then check to see if there is a file called mod_jk.conf in
c:\tomcat\tomcat-4-1-18\conf\auto
(c:\tomcat\tomcat-4-1-18\conf\auto\mod_jk.conf). If there is, all is well. If
there isn't, go back to the beginning of Step 5 and verify the changes you made
to server.xml.
<P>By adding the two Listener elements to server.xml, you are causing Tomcat to
generate the necessary Apache configuration directives for mod_jk automatically.
You don't need to type them by hand. This is a very convenient feature, but it
is optional. If you want to configure Apache by hand, you are welcome to do so,
but that is not covered here in this HOWTO.
<P>6. Almost done on the Tomcat side. JK, in the Apache module, uses the concept
of a "worker" to send and receive info to Tomcat. We need to tell the worker
where Tomcat is, and what port we want it to use. This is done with a
workers.properties file. We want to put the workers.properties file into
c:\tomcat\Tomcat-4-1-18\conf\jk, though it can be anywhere. So, open up Notepad
or your favorite text editor with a blank file, and add the following lines to
it:
<P>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR bgColor=#cccccc>
<TD><CODE># BEGIN workers.properties<BR># Definition for Ajp13
worker<BR>worker.list=ajp13<BR>worker.ajp13.port=8009<BR>worker.ajp13.host=localhost<BR>worker.ajp13.type=ajp13<BR>#
END workers.properties<BR></CODE></TD></TR></TBODY></TABLE>
<P>Save the file as c:\tomcat\Tomcat-4.1.18\conf\jk\workers.properties. Note
that the default name for a JK worker is "ajp13". You can call it what you like,
but my advice is don't change it until you have a completely working
installation and can see how all the pieces fit together.
<P>7. Now go back to Apache's httpd.conf file, and edit it
(c:\apache\Apache2\conf\httpd.conf). At the very end of the file, add the
following line:
<P>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR bgColor=#cccccc>
<TD><CODE>Include
c:/tomcat/tomcat-4-1-18/conf/auto/mod_jk.conf<BR></CODE></TD></TR></TBODY></TABLE>
<P>Save the file, and verify your syntax by running
<B>c:\apache\apache2\bin\apache.exe -t</B> at a command prompt. You should see a
message that says "Syntax OK". If you don't see this message, review the edits
you just made and make sure that c:/tomcat/tomcat-4-1-18/conf/auto/mod_jk.conf
and workers.properties actually exist where they should.
<P><B>Installation Checklist</B>
<P>OK, that was a lot of work. By now, you should have the following
environment:
<P>
<UL>
<LI>JDK installed in c:\j2sdk1.4.1_01
<LI>JAVA_HOME environment variable set for all users (System level) to
c:\j2sdk1.4.1_01
<LI>The JK DLL downloaded from the Jakarta site and placed in
c:\apache\Apache2\modules
<LI>Apache installed in c:\apache\apache2, with "Syntax OK" messages after
both the LoadModule edit and the Jk/Include edit, and able to view the Apache
welcome page at <A href="http://localhost/">http://localhost/</A>
<LI>Tomcat installed in c:\tomcat\tomcat-4-1-18, successfully restarted with
both Listener element edits to server.xml, and able to view the Tomcat welcome
page and execute the Tomcat examples at <A
href="http://localhost:8080/">http://localhost:8080/</A>
<LI>A file called workers.properties located in
c:\tomcat\Tomcat-4-1-18\conf\jk </LI></UL>
<P><B>Checking Your Installation</B>
<P>1. Start Tomcat as a service using the service control panel.
Start->Application Tools->Services. If Tomcat is running, stop it and then
start it. Wait a few seconds before continuing.
<P>2. Start Apache using the Apache Monitor in your System Tray. Right click on
the System Tray icon, and choose "Open Apache Monitor", then click "Start". Wait
a few seconds before continuing.
<P>3. Verify the Apache welcome page at <A
href="http://localhost/">http://localhost/</A>
<P>4. Verify the Tomcat examples at <A
href="http://localhost:8080/examples/jsp/index.html">http://localhost:8080/examples/jsp/index.html</A>
<P>5. Verify Tomcat examples available on port 80 at <A
href="http://localhost/examples/jsp/index.html">http://localhost/examples/jsp/index.html</A>
<P>If you can execute the Tomcat examples successfully without "8080" on the
URL, then mod_jk is working correctly.
<P>For more info, consult the Tomcat documentation as well as the tomcat-user
mailing list. If you want to use this HOWTO for something other than
"localhost", then all you have to do is use "www.your-domain.com" everywhere it
says "localhost". My advice in that scenario would be to copy the existing,
default Host container in Tomcat's server.xml, and change the "name" parameter
to "www.your-domain.com", then restart Tomcat (to re-gen mod_jk.conf with the
new hostname) and restart Apache. Making a copy of the localhost Host container
in server.xml will leave the localhost container as a failsafe default, which
might cut down on problems in the future.
<P>NOTE: in Tomcat, virtual hosts are "Hosts". That is, as far as Tomcat is
concerned, localhost <B>is</B> a virtual host. So, if you want to setup
www.server-a.com and www.server-b.com, you just need more copies of the Host
container included in the default server.xml that comes with Tomcat. Doing it in
production is a little more complicated than that, but that's the essence of how
to get Tomcat to work for more than localhost. Because this HOWTO describes
using the Apache auto-config option of JK, getting Tomcat to work with your
virtual hosts means Apache will work. This means that you can test your URL and
your application contexts using ":8080" on your URL without affecting Apache.
When you have it working, simply restart Apache so that it picks up the new
mod_jk.conf file generated by Tomcat and you should be well on your way.
<P><A href="http://www.johnturner.com/howto/apache-tomcat-howto.html">Back To
Menu</A>
<P>Please send comments, suggestions, or changes to john AT johnturner DOT com.
Be advised that I will be happy to help where I can, but I am not available for
free one-on-one tech support to the whole world. :)
<P>
<DIV align=center>
<H6>Copyright © 2002 John Turner. All rights reserved.</H6></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -