Integrating with Apache

I l @ ve RuBoard

Theoretically, you could deploy your application entirely on Tomcat. In fact, for low volume sites, this is entirely appropriate. For one of several reasons, however, you might want to layer Tomcat under Apache. These reasons are as follows :

  • To offload the mundane serving of static pages and images to the more efficient Apache server

  • Because you want to host sites under several virtual hostnames

  • Because you want to use SSL

Integrating Apache and Tomcat is fairly simple, if you follow the rules. First, you will need a copy of Apache for your architecture. If you're running Linux, you might already have it installed; otherwise , you can grab an RPM from one of the many sources on the Web (including www.apache.org) and install it according to the instructions provided with the software. After it's installed, you need to edit /etc/httpd/conf/httpd.conf and set the basic information about your server name and such. You can then start it up with the command /etc/init.d/httpd start . You can make it start every time you boot by copying that file to your rc.6 (or whatever the appropriate run level is for your Linux installation).

For Win32, you download either the .msi or the .exe files from the Apache Web site (www.apache.org) and install the appropriate file. The install will prompt you for your network domain, server name, and administrator's e-mail address. It will also ask if it should be made available to all users or only to you. Usually, you would select all users.

After it is installed, you'll have a Web server running on port 80 with a basic blank Web site. Now you're ready to integrate with Tomcat.

To do this, you will need the mod_webapp module, which is downloadable from http://jakarta.apache.org/builds/jakarta-tomcat-4.0/release/v4.0/bin/.

You should select the appropriate version for your operating system and extract the mod_webapp.so module. Under Windows, it goes into \Program Files\Apache Group \Apache\modules ( assuming that this is where you installed it). Under Linux, it goes in /etc/httpd/modules. For Windows, you also have to put libapr.dll in the same directory.

Now bring up an editor on httpd.conf, which is in either \Apache\conf for Windows or /etc/httpd/conf for Linux. Look for the end of the section of LoadModule directives and add the following:

 LoadModule webapp_module     modules/mod_webapp.so 

Then find the end of the section of AddModule directives and add the following:

 AddModule mod_webapp.c 

If the AddModule directives are above the LoadModule directives in your httpd.conf, put the LoadModule line in with the rest of the LoadModule directives and insert the AddModule directly under it. The AddModule directive must come second.

Now restart Apache (either /etc/init.d/httpd restart in Linux or using the option off the Apache program group in Windows). You shouldn't get an error message of any kind. If you do, double-check the location of the modules and the directives that you added.

Now check your Tomcat server.xml configuration file and make sure that this section is uncommented:

 <!-- Define an Apache-Connector Service -->   <Service name="Tomcat-Apache">     <Connector className="org.apache.catalina.connector.warp.WarpConnector"      port="8008" minProcessors="5" maxProcessors="75"      enableLookups="true"      acceptCount="10" debug="0"/>     <!-- Replace "localhost" with what your Apache "ServerName" is set to -->     <Engine className="org.apache.catalina.connector.warp.WarpEngine"      name="Apache" defaultHost="localhost" debug="0" appBase="webapps">       <!-- Global logger unless overridden at lower levels -->       <Logger className="org.apache.catalina.logger.FileLogger"               prefix="apache_log." suffix=".txt"               timestamp="true"/>       <!-- Because this Realm is here, an instance will be shared globally -->       <Realm className="org.apache.catalina.realm.MemoryRealm" />     </Engine>   </Service> 

You need to replace localhost with whatever your actual hostname is, which is the same thing that Apache was configured with for the server name. If you're just testing locally, localhost will do for both.

Restart Tomcat ”it must be running to start Apache when the following change is made.

Now go back to your httpd.conf file. You're going to configure your Books for Geeks site to be served via Apache. To do this, you should add the following to the end of the httpd.conf file:

 WebAppConnection conn      warp  localhost:8008 WebAppDeploy     bfg  conn  /bfg/ 

This tells Apache to pass anything coming in with a URL starting with /bfg to the Tomcat server listening on port 8008. This is the warp connector port, not the normal port that Tomcat uses when serving pages to the Web.

Unfortunately, things are reported to still be a little shaky for this feature, at least on the Windows side (it works fine under Linux). Specifically, there have been reports of communication failures between the two sides (Apache and Tomcat) under loaded conditions.

I l @ ve RuBoard


MySQL and JSP Web Applications. Data-Driven Programming Using Tomcat and MySQL
MySQL and JSP Web Applications: Data-Driven Programming Using Tomcat and MySQL
ISBN: 0672323095
EAN: 2147483647
Year: 2002
Pages: 203
Authors: James Turner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net