Rob,

I noticed you are having to use external redirects with mod_rewrite to get 
it to work with Tomcat.  This requirement, in my opinion, is the result of 
an over-zealous interpretation of Sun's servlet API specification which 
ends up forcing users to look at ugly, less-informative (from their 
perspective) URI's in their browser's location bar.  It's also bad news for 
people who need to communicate easy-to-remember URI's with each other (e.g. 
over the phone or on a business card).

To get around this, I was able to successfully hack the mod_webapp Apache 
1.3 module, and it appears to be working just fine with multiple instances 
of Tomcat running on the same server.  I haven't looked at mod_jk or the 
Apache 2.0 version of mod_webapp, but I imagine the required hacks would be 
similar.  If you're interested, let me know and I'll forward the code.

Regards,
Dan Lindy


At 05:10 PM 3/14/02 -0600, Robert Walther wrote:
>Hello All,
>
>I have been looking through the email archives to get instruction on how
>to set-up multiple instances of Tomcat on a single machine.  I found lots
>of good emails but no single source for what I wanted to accomplish.
>With the information I gathered, I was able to get a working system, where
>I can start and stop Tomcat independently of other Tomcat instances.  In
>the process, I also put together a document of the procedure I used.  This
>document follows below.
>
>If possible, I would really appreciate any feedback.  The system described
>below works, but I'm still not convinced it is the best configuration.  I
>hope, in any event this document may help others as well.
>
>PLEASE NOTE, this document is a draft version and does not offer any
>gaurantees to anyone if they choose to use it for building their own
>sites.
>
>I hope to include comments into this document as time goes by and keep
>updating it for everyone.  Thanks in advance for any comments and I hope
>this Open Source Community can benefit from it.
>
>Document Follows:
>
>Our Environment:
>Hardware                                                Software
>System:         Interserv90                     OS:             TurboLinux 
>Server 7.0
>Processor:      PIII 450Mhz                     Kernel: 2.4.9
>Ram:            256M                            Web Server:     Apache 
>1.3.22-2
>SWAP:   520M                            Java            jdk 1.3.1_02
>                                                 JServer Tomcat 3.2.4
>                                                 Connector       mod_jk.so 
> (ajp12 + ajp13)
>Prerequisites:
>�       You must have already installed both jdk 1.3.1_02 and tomcat 3.2.4.
>�       JAVA_HOME should be set to the directory in which jdk 1.3.1_02 is
>installed.
>In this example the java rpm installed java into /usr/java and then 
>we:
>ln
>         JAVA_HOME=/java; export JAVA_HOME
>
>�       TOMCAT_HOME should be set to the directory in which tomcat-3.2.4 is
>installed.
>In this example we installed tomcat into /usr/local/src and then:
>ln
>TOMCAT_HOME=/tomcat; export TOMCAT_HOME
>
>�       Set JAVA_HOME and TOMCAT_HOME in /etc/profile, so they reset on each
>reboot.
>�       Get the appropriate mod_jk from. (either mod_jk-eapi or mod_jk-noeapi)
>http://jakarta.apache.org/builds/jakarta-tomcat/release/v3.2.3/bin/linux/i386/
>               rename it to mod_jk.so
>               place it in apache
>�libexec�
>
>In this example we downloaded mod_jk-eapi to /root
>                 mkdir /etc/httpd/libexec
>mv /root/mod_jk-eapi /etc/httpd/libexec/mod_jk.so
>
>Note, If you downloaded the wrong mod_jk, apache will tell you upon its
>next startup.  There are only two to choose from, simply go back and get
>the other one to use.
>
>
>Note:
>Although, not entirely necessary, this document instructs that a separate
>directory be set-up for each JVM in order to better separate the
>functionality of each JVM.  For this example, the individual JVM
>directories have been placed under a new directory called /contexts.
>Although we will have a separate directory for each JVM under /contexts,
>we still only have one TOMCAT_HOME.  You do not need to set a TOMCAT_HOME
>for each JVM.
>
>
>Procedure:
>(Two new and INDEPENDENT JVM
>example below.  Instructions that include �site#� apply to both sites)
>
>1. Make �/contexts� and create a new directory for each site within
>/contexts.
>
>mkdir /contexts
>cd /contexts
>mkdir site1
>mkdir site2
>
>2. Copy the contents of your original Tomcat Installation into each site
>directory.
>
>         cp -R /$TOMCAT_HOME  /contexts/site1
>cp -R /$TOMCAT_HOME  /contexts/site2
>
>3. You should now have the following directories & files in each site
>directory:
>
>ls -p /contexts/site#
>
>bin/            doc/            lib/            logs/ 
>src/            work/
>conf/           KEYS            LICENSE         RELEASE-NOTES   webapps/ 
>
>
>4. set-up your �ajp� workers that will eventually be used by apache to
>redirect requests to Tomcat.  Using a text editor, modify the
>/$TOMCAT_HOME/conf/workers.properties file.  Note: this is the only
>workers.properties file that you have to modify.  Ignore the
>workers.properties files in the �conf� directories below /contexts/site#.
>
>In this example, we made the following changes to:
>/$TOMCAT_HOME/conf/workers.properties
>
>a. set
>workers.java_home=/java
>
>b. set
>workers.tomcat_home=/tomcat
>
>c. comment out ps=\ and uncomment ps=/
>#ps=\
>ps=/
>
>d. set-up two new workers for each JVM.  There is no harm in leaving the
>default workers (ajp12 & ajp13) in here, but we will not be using them in
>this example.
>worker.list=ajp12, ajp13, ajp12_site1, ajp12_site1, ajp13_site2,
>ajp13_site3
>
>                      default 
> workers                                       new workers
>
>
>
>4.Continued.
>
>e. Now, add the following four lines for each new worker (again, just
>ignore the default workers, they are already configured but will not be
>used). Be careful none of the workers are using the same port.
>
>  worker.ajp12_site1.port8010                            NOTES:
>  worker.ajp12_site1.host=localhost
>  worker.ajp12_site1.type=ajp12                          two ports to be 
> designated
>  worker.ajp12_site1.lbfactor=1                          later in 
> server.xml for site1
>
>  worker.ajp12_site1.port8011
>  worker.ajp12_site1.host=localhost
>  worker.ajp12_site1.type=ajp13
>  worker.ajp12_site1.lbfactor=1
>
>  worker.ajp12_site2.port8012
>  worker.ajp12_site2.host=localhost
>  worker.ajp12_site2.type=ajp12                          two ports to be 
> designated
>  worker.ajp12_site2.lbfactor=1                          later in 
> server.xml for site2
>
>  worker.ajp12_site2.port8013
>  worker.ajp12_site2.host=localhost
>  worker.ajp12_site2.type=ajp13
>  worker.ajp12_site2.lbfactor=1
>
>Your workers.properties file has now been configured. Later these workers
>will be used in apache to handle connections destined for Tomcat.  You can
>add as many workers as you want in this manner.  Note: you could just use
>ajp12 type by itself, but the ajp13 type is faster.  The reason we use
>both, is because the ajp12 type worker is still needed in the shutdown
>process of Tomcat.  In addition, you can load balance your workers, even
>across different machines. That topic, however, extends beyond the scope
>of this document.
>
>5. Each JVM has its own server.xml file located under
>/contexts/site#/conf.  You will need to modify the server.xml file for
>each JVM.
>
>a.  cd /contexts/site#/conf and open the server.xml file with your
>favorite editor.
>
>b. Move the three (3) <Logger > directives to the bottom of each of the
>server.xml  files, (after </Context Manager> but before </Server>).  If
>you do not move these Logger directives, your log files will be placed in
>the original /$TOMCAT_HOME/log directory, rather than the
>/contexts/site#/log directory, and the whole JVM may error.
>
>c. Modify the <ContextManager � > line in each server.xml file to reflect
>the settings for each site.
>
>site1's server.xml file would have the following line.  The following is a
>single line.
><ContextManager debug=�0� home=�/contexts/site1�
>workDir=�work_site1� showDebugInfo=�true� >
>
>site2's server.xml file would have the following line.  The following is a
>single line.
><ContextManager debug=�0� home=�/contexts/site2�
>workDir=�work_site2� showDebugInfo=�true� >
>
>
>5. Continued
>
>d. Modify the <!- - =======  Connectors ======= - -> section.
>
>i. comment out the <Connector> for port 8080 in both server.xml files,
>otherwise both JVMs will attempt to connect to the 8080 port.  You would
>get an error when you try to start your second JVM.
>
><!--
>         <Connector className=�org.apache.tomcat.service.PoolTCPConnector�>
>                 <Parameter
>name=�handler� 
>value=�org.apache.tomcat.service.http.HttpConnectionHandler�/>
>                 <Parameter name=�port�
>value=�8080� />
>                 </Connector>
>-->
>
>
>ii. modify the ajp12 and ajp13 connectors, and assign them the appropriate
>ports as they
>     were set-up in the workers.properties file.
>
>server.xml file for site1
><!--comments, etc -->
><Connector className=�org.apache.tomcat.service.PoolTCPConnector�>
>                 <Parameter
>name=�handler� 
>value=�org.apache.tomcat.service.http.Ajp12ConnectionHandler�/>
>                 <Parameter name=�port� value=�8010� />
></Connector>
>
><!--comments, etc -->
><Connector className=�org.apache.tomcat.service.PoolTCPConnector�>
>                 <Parameter
>name=�handler� 
>value=�org.apache.tomcat.service.http.Ajp13ConnectionHandler�/>
>                 <Parameter name=�port� value=�8011� />
></Connector>
>
>
>server.xml file for site2
><!--comments, etc -->
><Connector className=�org.apache.tomcat.service.PoolTCPConnector�>
>                 <Parameter
>name=�handler� 
>value=�org.apache.tomcat.service.http.Ajp12ConnectionHandler�/>
>                 <Parameter name=�port� value=�8012� />
></Connector>
>
><!--comments, etc -->
><Connector className=�org.apache.tomcat.service.PoolTCPConnector�>
>                 <Parameter
>name=�handler� 
>value=�org.apache.tomcat.service.http.Ajp13ConnectionHandler�/>
>                 <Parameter name=�port� value=�8013� />
></Connector>
>
>
>5. Continued
>
>e. Under the <!-- ======  special webapps  ======= --> section, and after
>the <Context> directives, add a virtual host for each site in their
>respective server.xml files.  Note, each site has its own directory under
>/contexts and each site will have its own contextname under
>/context/webapps.  You can make this contextname anything you want.
>
>i. in server.xml for site1, where site1
>
><Host name=�192.168.1.100�>
>    <Context path=�/site1contextname�
>docBase=�webapps/site1contextname�
>                                 debug=�0� />
>                 </Host>
>
>i. in server.xml for site2, where site1
>
><Host name=�192.168.1.200�>
>         <Context path=�/site2contextname�
>docBase=�webapps/site2contextname�
>                                 debug=�0� />
>                 </Host>
>
>f.  Your server.xml files are now configured.  These files will be used
>when you start and stop Tomcat.  You may want to rename these files so you
>can better differentiate between them. Example�
>
>                 cd /context/site1/conf
>                 mv server.xml server_site1.xml
>
>cd /context/site2/conf
>                 mv server.xml server_site2.xml
>
>
>
>6. You are now ready to modify Apache to use the workers to send requests
>to Tomcat.
>
>a. Open httpd.conf with your favorite text editor.  On my TurboLinux 7.0,
>this file is located in /etc/httpd/conf.
>
>b. add the following lines that will be required for apache to load and
>use mod_jk.so.
>
>LoadModule jk_module    libexec/mod_jk.so
>AddModule       mod_jk.c
>
>c. add the following lines that will be required to tell apache where to
>get worker configurations and where & how to log.
>
>#Configure mod_jk
>JkWorkersFile   /tomcat/conf/workers.properties
>JkLogFile               /tomcat/logs/mod_jk.log
>JkLogLevel              error
>
>
>6. Continued
>
>d. configure your vitual hosts in httpd.conf
>
>excerpt from httpd.conf....
>
>  # Virtual Host for site1
>
>  <VirtualHost 192.168.1.100:80>
>         DocumentRoot �/contexts/site1/webapps/site1contextname
>         ServerName site1.yourdomain.com
>         ServerAdmin email of server admin
>         JkMount /* ajp13_site1
>         JkMount /servlet/* ajp13_site1
>         JkMount /site1contextname/*.jsp ajp13_site1
>         RewriteEngine On
>         RewriteRule ^/$ /site1contextname/index.jsp [NC,R]
>  </VirtualHost>
>
>  # Virtual Host for site2
>
>  <VirtualHost 192.168.1.200:80>
>         DocumentRoot �/contexts/site2/webapps/site2contextname
>         ServerName site2.yourdomain.com
>         ServerAdmin email of server admin
>         JkMount /* ajp13_site2
>         JkMount /servlet/* ajp13_site2
>         JkMount /site2contextname/*.jsp ajp13_site2
>         RewriteEngine On
>         RewriteRule ^/$ /site2contextname/index.jsp [NC,R]
>  </VirtualHost>
>
>
>Ultimately, any requests that come in, Apache will determine if they
>should be sent to one of the virtual hosts.  Inside the virtual host, if
>that request matches anyone of the mount points designated by JkMount,
>that request will be sent to the associated worker.
>
>Note: The above virtual hosts from httpd.conf use mod_rewrite directives
>to redirect the incoming URL requests to the appropriate context.  Tomcat
>can handle the redirection, but I found it easier to have Apache do it
>here. The R informs rewrite to redirect the request and the NC tells it
>not to be case sensitive.
>
>For example a client that requests:
>  http://site1.Yourdomain.com/
>
>They will be automatically redirected to:
>http://site1.Yourdomain.com/site1contextname/index.jsp
>
>In order for the rewrite directives to work, make sure you have a
>LoadModule and AddModule line for mod_rewrite.so in your httpd.conf file.
>Most all apache web servers today have the rewrite module included by
>default.
>
>7. Starting and Stopping the Independent JVMs
>
>To start site1, do the following:
>cd /contexts/site1/bin
>./startup.sh
>
>To shutdown site1, do the following:
>cd /contexts/site1/bin
>./startup.sh
>
>
>
>To start site2, do the following:
>cd /contexts/site2/bin
>./startup.sh
>
>To shutdown site2, do the following:
>cd /contexts/site2/bin
>./startup.sh
>
>
>Note, everytime you add a new site, you must restart apache.  To enhance
>security for you sites, you can add an .htaccess file in the /contexts
>directory that designates additional directory, location and file
>container directives.  Consult you Apache documentation on how to set up
>.htaccess files.  Lastly, you will find helpful security directives in the
>auto-generated mod_jk-auto.conf. that you can copy into your .htaccess
>file.  The mod_jk-auto.conf file is not needed when you have multiple JVMs
>(aka. Multiple Tomcat Instances).  Even-though this file is not used in
>this example, it is still generated by default in Tomcat 3.2.4.  In fact
>many of the files in your /contexts/site#/conf directory are not used in
>this example.
>
>
>Thanks for Reading!
>
>Rob Walther
>
>
>--
>To unsubscribe:   <mailto:[EMAIL PROTECTED]>
>For additional commands: <mailto:[EMAIL PROTECTED]>
>Troubles with the list: <mailto:[EMAIL PROTECTED]>


--
To unsubscribe:   <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>

Reply via email to