tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Robert L Sowders" <>
Subject Re: [HOWTO] VIRTUAL HOSTING, APACHE 2.0.43, JK2, TOMCAT 4.1.12
Date Tue, 22 Oct 2002 23:56:45 GMT
Nice going Umberto,

Umberto Nicoletti <>
10/22/2002 07:07 AM
Please respond to "Tomcat Users List"

        Subject:        [HOWTO] VIRTUAL HOSTING, APACHE 2.0.43, JK2, TOMCAT 4.1.12

I posted to this mailing list before with the subject: JK2 connector and
virtual hosting,
but got no answer.

After some more reading through the ML archives and the documentation
I eventually came up with a solution.
Just to annoy some more people I wrote a little HOWTO ;-).

Hope it will be useful to somebody.

Umberto Nicoletti - |
Tel. 049-8239380 (assistenza)

"We'll try to make different mistakes this time." - Larry 
Apache 2.0.43 - Tomcat 4.1.12 - jk2 - virtual host HOWTO

Tue 22 Oct 2002 11:58:28 AM GMT-5 
Umberto Nicoletti [unicoletti at]


Insert usual disclaimer here.

unusual disclaimer
Please forget:
1) my English
2) typos
3) names of hosts and installation directories

Also be warned that this is a beta version I just wrote as a reminder. if 
encounter errors or discrepancies between what it is written here and what 
happens to
you following this howto (or just want to point out something more 
clearly) please
email me a corrected version of this HOWTO.

/unusual disclaimer


RedHat Linux 7.2
Latest 1.4.x Sun JDK:
#java -version
                 java version "1.4.1_01"
                 Java(TM) 2 Runtime Environment, Standard Edition (build 
                 Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed 
Tomcat 4.1.12 binary
Apache 2.0.43 built from source
                 [./configure -prefix=/usr/local/apache2.0.43 
--sysconfdir=/etc/apache --localstatedir=/var --disable-dav --enable-so 
--enable-proxy --enable-proxy-connect --enable-proxy-http]
jk2 connector binary from


Deploy three (in my case) web applications under three different virtual 
hosts, making the default vhost
respond to any name and to the bare IP address.


Download all the packages listed above, get a mug of hot coffee (or beer 
if you're German),
do what I say here and you'll be just fine.


Note: download the jdk, not just the jre!
Uncompress the jdk somewhere in the filesystem:
I chose /usr/local/:

[root@ARLIN72AGE279 apache]# ll /usr/local/ 
total 48
lrwxrwxrwx    1 root     root           13 Oct 18 17:20 apache -> 
drwxr-xr-x   15 root     root         4096 Oct 21 16:40 apache2.0.43
drwxr-xr-x    2 root     root         4096 Feb  6  1996 bin
drwxr-xr-x    2 root     root         4096 Feb  6  1996 doc
drwxr-xr-x    2 root     root         4096 Feb  6  1996 etc
drwxr-xr-x    2 root     root         4096 Feb  6  1996 games
drwxr-xr-x    2 root     root         4096 Jun 22  2001 include
drwxr-xr-x    9 root     root         4096 Oct 18 16:37 j2sdk1.4.1_01
lrwxrwxrwx    1 root     root           14 Oct 18 16:38 java -> 
drwxr-xr-x    2 root     root         4096 Feb  6  1996 lib
drwxr-xr-x    2 root     root         4096 Jun 22  2001 libexec
drwxr-xr-x    2 root     root         4096 Feb  6  1996 sbin
drwxr-xr-x    4 root     root         4096 Oct 18 13:07 share
drwxr-xr-x    2 root     root         4096 Feb  6  1996 src

make a symlink named java to  j2sdk1.4.1_01/ so that you can easily switch 
back and forth
between different jvms. We will use the same trick for apache and tomcat 

Now tell your bash shell where to find java binaries: create a file named in
/etc/profile.d with the following content:

[root@ARLIN72AGE279 apache]# cat /etc/profile.d/ 
# set java environment

export JAVA_HOME=/usr/local/java
export PATH=$PATH:$JAVA_HOME/bin


do a chmod:
#chmod 700 /etc/profile.d/

Now open a new shell and try this:
[root@ARLIN72AGE279 apache]# which java

You should get the answer given above. If not chek your environment and 
make sure that is executed
when opening a new shell.
Try to run a java program or the following: java -version.

If you don't like this way of installing java please ignore it.

Make sure everything is ok and then jump to next step.


Download the latest release, uncompress it, cd into the newly created 
directory and run the following:
[root@ARLIN72AGE279 apache]# ./configure -prefix=/usr/local/apache2.0.43 
--sysconfdir=/etc/apache --localstatedir=/var --disable-dav --enable-so

Of course you can customize the installation specifying other modules to 
enable or whatever you like.
Just don't forget to ENABLE-SO, because that's what you need to load the 
apache-tomcat connector.

Run make and make install. Create the log directories and others (you can 
skip this if you know how
to configure where apache puts its log files -> edit httpd.conf):

#mkdir /var/logs
#mkdir /usr/local/apache2.0.43/conf
#mkdir /usr/local/apache2.0.43/logs

Create the symlink /usr/local/apache to /usr/local/apache2.0.43 and test 
your installation
by executing:

#/usr/local/apache/bin/apachectl start

Open a browser and point it to the linux box: you should get a page 
telling you that the apache installation
was successful.
If not check the logs and troubleshoot: common errors in this 
are that some directory holding log or configuration files is missing.


Uncompress the tomcat binaries in a directory of your choice. In this 
howto we will use /opt.
Create a symlink named jakarta to the newly created directory so that you 
have something like the following:

[root@ARLIN72AGE279 root]# ll /opt/
total 4
lrwxrwxrwx    1 root     root           31 Oct 18 16:38 jakarta -> 
drwxr-xr-x   12 root     root         4096 Oct 18 18:10 

Start tomcat by running /opt/jakarta/bin/ After a few seconds 
point your browser at the IP of
the linux box on port 8080 and you should see the tomcat welcome page.
If not check the catalina.out log file in /opt/jakarta/logs and fis all 
errors until Tomcat comes up.


Here is a sample server.xml file. Please note that the location of 
directories and log files is absolutely
arbitrary and you have to edit it to make it suit your needs.

<!-- Umberto Server Configuration File -->

<Server port="8005" shutdown="SHUTDOWN" debug="0">
  <!-- Define an Apache-Connector Service -->

  <Service name="Tomcat-Apache">
   <!-- Define a Coyote/JK2 AJP 1.3 Connector on port 8009 -->
    <Connector className="org.apache.coyote.tomcat4.CoyoteConnector"
               port="8009" minProcessors="5" maxProcessors="75"
               enableLookups="true" redirectPort="8443"
               acceptCount="10" debug="0" connectionTimeout="20000"

                 <Engine name="Apache" defaultHost="" 

      <Logger className="org.apache.catalina.logger.FileLogger"
              prefix="apache_log." suffix=".txt"
                   <!-- Access log processes all requests for this virtual 
host. -->
      <Valve className="org.apache.catalina.valves.AccessLogValve"
                 directory="logs"  prefix="localhost_access_log." 
                 pattern="common" resolveHosts="false"/>

                 <Host name="" debug="0" 
       unpackWARs="true" autoDeploy="true">

                                 <Context path="" docBase="" debug="1"/>

                 directory="logs"  prefix="home_access_log." suffix=".txt"
                 pattern="common" resolveHosts="false"/>

                 <Host name="" debug="0" 
       unpackWARs="true" autoDeploy="true">

                                 <Context path="" docBase="" debug="1"/>

                 directory="logs"  prefix="cust1_access_log." 
                 pattern="common" resolveHosts="false"/>

                 <Host name="" debug="0" 
       unpackWARs="true" autoDeploy="true">

                                 <Context path="" docBase="" debug="1"/>

                 directory="logs"  prefix="cust2_log." suffix=".txt"
                 pattern="common" resolveHosts="false"/>




This is a very minimalistic conf file, because we have taken away the 
HTTP1.1 connector that allows us to talk directly to Tomcat.
It might not be good for development, but it should be good for 
If you feel like you need also the Tomcat Standalone service then copy and 
paste it from your original server.xml file
(you did back it up, didn't you?).

Try to start tomcat again and check catalina.out to see if everything is 
up and running. If it complains about
missing apr stuff try to edit /opt/jakarta/conf/ and make it 
look so:

# list of needed handlers.
# Override the default port for the channelSocket

If everything is ok move on to next section.


In the appendix you can find the httpd.conf file I used to write and test 
this HOWTO.


Download the jk2 shared library for you version of apache and copy it in 
(create the  directory if necessary). If you can't find a suitable version 
of jk2 ask it to the tomcat-user ml
or download the source and build it yourself (this is another HOWTO).

Create, if you haven't already, the /usr/local/apache/conf directory and 
create a file named with this content in it:

# only at beginnin. In production uncomment it out


# Example socket channel, override port and host.

# define the worker

# Uri mapping



Edit the file, change ip addresses and names to suit your needs and save 

Edit http.conf and add the following line in the Modules section:
LoadModule jk2_module modules/

Save http.conf and try to start apache. It should now load the jk2 
connector and the configuration
Check the error log to make sure everything is ok.
Start tomcat and try to load a HTML page in your browser: apache should 
return the page
without problems.

Now try with a jsp page: it should display after a little.

If you get errors check that the path and host names (double check also 
the configuration of DNS
with your network administrator) are ok, the directories are readable by 
both Tomcat and Apache.
Again look into the log files.

If everything works go to next section.


Now ask your network administrator to set up an alias for your brand new 
server (use jspsrc if
you like to stick to this howto).
If you don't have easy access to dns try to edit your hosts file (on the 
client where you open the browser)
and add a line as follows:                                jspsrc

where is the ip of your server. Open your browser and type this 
in your location bar:


and navigate to a jsp page. You should get the source of the jsp page into 
your browser!
This is clearly a security problem, if not a major annoyance.

What's wrong with the setup we came up so far? The problem is (or should 
be) that the ajp13
connector can't find a virtual host that matches the jspsrc uri.
What we need to do is set up the default virtual host so that ALL *.jsp 
requests get handled by tomcat.
How do we do it?


In addition to the you can put Jk diretives directly 
into the httpd.conf file (just as you did
with jk and webapp).
Edit the default virtual host section in httpd.conf and add the following 
lines in the end, before

    <Location "/*.jsp">
        JkUriSet worker ajp13:localhost:8009 

Restart Apache and test the jspsrc url again.
The jsp source should not be displayed anymore.


I think a better approach would be to remove all uri directives from
and to put them in http.conf as we did in the previous section for the 
defualt virtual host.
Experiment and let me know.

APPENDIX A: httpd.conf
# Umberto Nicoletti, 18/10/2002

### Section 1: Global Environment

ServerRoot "/usr/local/apache"
ErrorLog logs/error_log

<IfModule !mpm_winnt.c>
<IfModule !mpm_netware.c>
#LockFile logs/accept.lock

# ScoreBoardFile: File used to store internal server process information.
<IfModule !mpm_netware.c>
<IfModule !perchild.c>
#ScoreBoardFile logs/apache_runtime_status

<IfModule !mpm_netware.c>
PidFile logs/

Timeout 300

KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 15

<IfModule prefork.c>
StartServers         5
MinSpareServers      5
MaxSpareServers     10
MaxClients         150
MaxRequestsPerChild  0

<IfModule worker.c>
StartServers         2
MaxClients         150
MinSpareThreads     25
MaxSpareThreads     75 
ThreadsPerChild     25
MaxRequestsPerChild  0

<IfModule perchild.c>
NumServers           5
StartThreads         5
MinSpareThreads      5
MaxSpareThreads     10
MaxThreadsPerChild  20
MaxRequestsPerChild  0

# listen on all ports
Listen 80

# Dynamic Shared Object (DSO) Support
LoadModule jk2_module modules/

### Section 2: 'Main' server configuration

<IfModule !mpm_winnt.c>
<IfModule !mpm_netware.c>
# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch. 
# User/Group: The name (or #number) of the user/group to run httpd as.
#  . On SCO (ODT 3) use "User nouser" and "Group nogroup".
#  . On HPUX you may not be able to use shared memory as nobody, and the
#    suggested workaround is to create a user www and use that user.
#  NOTE that some kernels refuse to setgid(Group) or semctl(IPC_SET)
#  when the value of (unsigned)Group is above 60000; 
#  don't use Group #-1 on these systems!
User nobody
Group #-1

ServerAdmin whatever@you.want
UseCanonicalName Off

# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" 
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

LogLevel debug
CustomLog logs/access.log common

DocumentRoot "/opt/jakarta-tomcat-4.1.12-LE-jdk14/webapps/struts-example"

<Directory /opt/jakarta-tomcat-4.1.12-LE-jdk14/webapps/struts-example>
    Options None
    AllowOverride None

DirectoryIndex index.html index.jsp

<Directory />
    Options None
    AllowOverride None

<Files ~ "^\.ht">
    Order allow,deny
    Deny from all

<Location /WEB-INF/>
    Order Allow,Deny

NameVirtualHost *

<VirtualHost *>
                 ServerAlias www
                 ServerAlias localhost

    ErrorLog logs/
                 CustomLog logs/ common


<VirtualHost *>
    DocumentRoot /opt/jakarta-tomcat-4.1.12-LE-jdk14/webapps/struts-blank
    ErrorLog logs/cust1-errorlog

<VirtualHost *>
    DocumentRoot /opt/jakarta-tomcat-4.1.12-LE-jdk14/webapps/root
    ErrorLog logs/cust2-errorlog

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message