Tomcat-Apache HOWTO Tomcat+Apache HOWTO

 

Tomcat-Apache HOWTO

This document explains how to connect Tomcat to the popular open source web server, Apache. It was originally part of Tomcat: A Minimalistic User's Guide by Gal Shachor, but has been split off for organizational reasons. It should be considered a work in progress. Since the Tomcat source tree is constantly changing, the information herein may be out of date. The only definitive reference at this point is the source code.

Other important documents:

  • Tomcat User's Guide
  • mod_jk HOWTO [??? should be rolled into tomcat-apache howto]
  • Jakarta FAQ Page

Other Tomcat-Apache HOWTOs: [should be integrated into this one?]

  • Howto Configure Tomcat 3.1 with Apache by Freddie Mendoza
  • Apache Web Server / JServ / Tomcat / SSL Installation on UNIX by Jan K. Labanowski
  • Tomcat and JServ by Jun Inamori
  • http://www.dmz.hitachi-sk.co.jp/Java/Tech/servlet/tomcat.html in Japanese

Table of Contents

  • [write me]

Apache - Tomcat Cooperation - Sample Server Integration

Up until now we have not discussed Tomcat as a server add on, instead we have considered it as a stand-alone container and discussed how it can be used.  There are however a few problems with this picture:

  1. Tomcat is not as fast as Apache when it comes to static pages.
  2. Tomcat is not as configurable as Apache.
  3. Tomcat is not as robust as Apache.
  4. There are many sites with long time investment in certain web servers, for example, sites that are using CGI scripts/Server API modules/perl/php.  We cannot assume that all of them will want to ditch this legacy.

For all these reasons it is recommended that real world sites use an industrial strength web server, such as Apache, for serving the static content of the site, and use Tomcat as a Servlet/JSP add-on.

Our agenda:

  1. Cover the fundamental behavior of the web server.
  2. Explain what configuration is needed.
  3. Demonstrate this on Apache.

Common Installation and Configuration Problems

This section isn't meant to be your one-stop shop for all troubles Tomcat, but a resource for stumbling blocks common to many first-time Tomcat'ers.  See the help section for additional links.

    http://webserver:8007/ gives a 500

This is what you should see in your tomcat.log file:

HANDLER THREAD PROBLEM: java.io.IOException: Stream broken

By default, Tomcat listens for AJP connections on port 8007.  AJP is the protocol used to communicate between the web server and Tomcat, not Tomcat and your browser.  To test your Tomcat installation, FIX ME ?

    and directives ignored

FIX ME Apache never applies because forwarded to Tomcat.

    Web server won't start when Tomcat is running

FIX ME Port conflict.

    "Bad command or filename" when executing Tomcat scripts

[FIX ME] UNIX file format on DOS.  Because Tomcat is developed on *nix (rather, the jars are built and distributed there), you may have to convert the files to PC (versus UNIX) format.


Starting Tomcat From Another Directory

Setting Tomcat to Cooperate with the Apache Web Server

Web Server Operation

In a nutshell a web server is waiting for client HTTP requests. When these requests arrive the server does whatever is needed to serve the requests by providing the necessary content. Adding a servlet container may somewhat change this behavior. Now the web server needs also to perform the following:

  • Load the servlet container adapter library and initialize it (prior to serving requests).
  • When a request arrives, it needs to check and see if a certain request belongs to a servlet, if so it needs to let the adapter take the request and handle it.
The adapter on the other hand needs to know what requests it is going to serve, usually based on some pattern in the request URL, and to where to direct these requests.

Things are even more complex when the user wants to set a configuration that uses virtual hosts, or when they want multiple developers to work on the same web server but on different servlet container JVMs. We will cover these two cases in the advanced sections.

What is the Needed Configuration

The most obvious configuration that one can think of is the identity of the servlet URLs that are under the responsibility of the servlet container. This is clear; someone must know what requests to transmit to the servlet container... Yet there are additional configuration items that we should provide to the web-server/servlet-container combination:

  • We also need to provide configuration regarding the available Tomcat processes and on which TCP/IP host/port they are listening.
  • We need to tell the web server the location of the adapter library (so it will be able to load it on startup).
  • W

你可能感兴趣的:(webapps,tomcat,apache,servlet,server,file,module)