0

Tomcat/Apache Integration with ZK-solved

asked 2006-08-17 12:43:50 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3871461

By: alanoneill

Thanks for the feedback, Henri. Actually, I did read that post, and I thought it was probably what I needed, but, being new to Tomcat, I didn't understand the details. In any event, after your reply, I read and reread the post and concentrated my focus on the details in it. For those who may be in the same boat as I was, I supply here the solution that I implemented.

First, I'm running Kubuntu Dapper Drake 6.06 with Apache 2.0 and Tomcat 5.
I also found that the Sun Java JDK (sun-java5-jdk) is MUCH faster than Kaffe, which appears to be the default for Kubuntu. It's available to Kubuntu by updating the repositories to include multiverse. I also found that even though I issued the command "update-alternatives --config java" and selected Sun's java, I still needed to update the /etc/default/tomcat5 file to point to the correct JDK.
I describe this point later in this reply.

Below is a detailed description of what I did to get Tomcat to work smoothly with Apache and mod_jk.

First, I installed the following packages:

apache2
tomcat 5
libapache2-mod-jk

I believe libservlet2.3-java and/or libservlet2.4-java may also be needed.
They are installed on my machine, and I have not experimented with removing them.

Next, I setup a few files as described below.

Filename = /var/lib/tomcat5/conf/uriworkermap.properties
--------------------[ Contents ]-------------------- # Assign specific URLs to Tomcat. In general the structure of a JkMount directive is # If mount point uri starts with minus character (-), the mount point will be disabled.
# If mount point uri starts with bang (!), the mount point is not mapped to Tomcat.
# At run time you can change the content of this file. For example removing minus char # will enable the uri mapping. You can add any number of new entries at runtime that # reflects the newly deployed applications. Apache will reload the file and update # the mount points within 60 seconds.
#
# The format of each line is
# uri=worker_name

# Map all ZK (*.zul) and all zkau files to worker1
/*.zul=worker1
/*/zkau*=worker1
----------------------------------------------------

Filename = /etc/apache2/conf.d/tomcat5.conf
Note: You may want to change "JkLogLevel" to "info" instead of "debug" as "debug"
will cause the log file to become rather large.
--------------------[ Contents ]-------------------- # Specify the location where mod_jk is going to place its log file

JkLogFile /var/log/tomcat5/mod_jk.log

# Set the log level:
# info - log will contain standard mod_jk activity (default).
# warn - log will contain non fatal error reports.
# error - log will contain also error reports.
# debug - log will contain all information on mod_jk activity
# trace - log will contain all tracing information on mod_jk activity

JkLogLevel debug

# Configure the date/time format found on mod_jk log file using the strftime() format string.

JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "

# Configure the format of mod_jk individual request logging.
# Request logging is configured and enabled on a per virtual host basis.
# To enable request logging for a virtual host just add a JkRequestLogFormat config.
# The syntax of the format string is similar to the Apache LogFormat command.
# Here is a list of the available request log format options:
# %b Bytes sent, excluding HTTP headers (CLF format)
# %B Bytes sent, excluding HTTP headers
# %H The request protocol
# %m The request method
# %p The canonical Port of the server serving the request
# %q The query string (prepended with a ? if a query string exists, otherwise
an empty string)
# %r First line of request
# %s Request HTTP status code
# %T Request duration, elapsed time to handle request in seconds '.' micro
seconds
# %U The URL path requested, not including any query string.
# %v The canonical ServerName of the server serving the request
# %V The server name according to the UseCanonicalName setting
# %w Tomcat worker name

JkRequestLogFormat "%w %V %T"

# Set forwarding options that will enable (+) or disable (-) an option.
# ForwardKeySize - ask mod_jk, when using ajp13, to forward also the SSL
Key Size
# as required by Servlet API 2.3. This flag shouldn't be set when
servlet
# engine is Tomcat 3.2.x (on by default)
# ForwardURICompat - Tell mod_jk to send the URI to Tomcat normally, which
is less
# spec compliant but mod_rewrite compatible, use it for compatibility
with
# Tomcat 3.2.x engines (on by default).
# ForwardURICompatUnparsed - Forwarded URI is unparsed, it's spec compliant
but
# broke mod_rewrite.
# ForwardURIEscaped - Forwarded URI is escaped and Tomcat (since 3.3 rc2)
will
# do the decoding part.
# ForwardDirectories - Used in conjunction with DirectoryIndex directive
of Apache
# web server. As such mod_dir should be available to Apache, statically
or
# dynamically.
#
# When DirectoryIndex is configured, Apache will create sub-requests
for each
# of the local-url's specified in the directive, to determine if there
is a local
# file that matches (this is done by stat-ing the file).
#
# If ForwardDirectories is set to false (default) and Apache doesn't
find any
# files that match, Apache will serve the content of the directory (if
directive
# Options specifies Indexes for that directory) or a 403 Forbidden response
(if
# directive Options doesn't specify Indexes for that directory).
#
# If ForwarDirectories is set to true and Apache doesn't find any files
that
# match, the request will be forwarded to Tomcat for resolution. This
is used in
# cases when Apache cannot see the index files on the file system for
various
# reasons: Tomcat is running on a different machine, the JSP file has
been
# precompiled etc.
#
# Note that locally visible files will take precedence over the ones
visible
# only to Tomcat (i.e. if Apache can see the file, that's the one that's
going to
# get served). This is important if there is more then one type of file
that Tomcat
# normally serves - for instance Velocity pages and JSP pages.
# ForwardLocalAddress - Tell mod_jk to send the local address of the Apache
web server
# instead of the remote client address. This can be used by Tomcat remote
address
# valve for allowing connections only from registered Apache web
servers.
# FlushPackets - Tell mod_jk to make a flush after each AJP packet received
from Tomcat.

JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

# Forward environment vars from Apache server to Tomcat engine.

# JkEnvVar SSL_CLIENT_V_START

# Automatically Alias webapp context directories into the Apache document space, which enables # Apache to serve a static context while Tomcat serving dynamic context. This directive is used # for convenience so that you don't have to put an apache Alias directive for each application # directory inside Tomcat's webapp directory.

JkAutoAlias /var/lib/tomcat5/webapps

# Define the JkWorkers

JkWorkerProperty worker.list=worker1
JkWorkerProperty worker.worker1.type=ajp13 JkWorkerProperty worker.worker1.host=localhost JkWorkerProperty worker.worker1.port=8009 JkWorkerProperty worker.worker1.socket_timeout=0 JkWorkerProperty worker.worker1.socket_keepalive=True
JkWorkerProperty worker.worker1.retries=3 JkWorkerProperty worker.worker1.connection_pool_size=1
JkWorkerProperty worker.worker1.connection_pool_minsize=2
JkWorkerProperty worker.worker1.connection_pool_timeout=0
JkWorkerProperty worker.worker1.lbfactor=50

# Define the dynamic updates of mount points at runtime. When the mount file is changed, JK # will reload it's content.

JkMountFile /var/lib/tomcat5/conf/uriworkermap.properties
----------------------------------------------------

Filename = /etc/apache2/apache2.conf
----------------------------------------
I added "index.zul" to the "DirectoryIndex" line. In my case, the line ended up reading as follows:

DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.zul
----------------------------------------

Filename = /etc/default/tomcat5
----------------------------------------
To allow Apache to serve pages that are outside of the document tree used by Apache, I turned security in Tomcat off by adding the following line to this file. Alternately, I could have specifically granted Apache access to /var/lib/tomcat5/webapps in the /etc/apache2/conf.d/tomcat5.conf file.

TOMCAT5_SECURITY=no

To make Tomcat use Sun Java instead of Kaffe, I added the following line to this file.

JAVA_HOME=/usr/lib/jvm/java-1.5.0-sun
----------------------------------------


delete flag offensive retag edit

5 Replies

Sort by ยป oldest newest

answered 2006-08-17 13:42:00 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3871551

By: henrichen

Thanks for sharing the solution. It is very useful.

/henri

link publish delete flag offensive edit

answered 2006-08-18 04:49:27 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3872854

By: tomyeh

Hi Alan,

It will be more helpful if you post it to How-tos at http://en.wikibooks.org/wiki/ZK/How-Tos#Apache_.2B_Tomcat

Thanks for your contribution.

Tom

link publish delete flag offensive edit

answered 2010-03-30 10:31:32 +0800

w2davids gravatar image w2davids
15 1

Hi,

I have a problem with processing/rendering of zk pages with Apache.

Basically, I have an SSL connection using Apache, but the zul pages are not interpreted and rendering.
I am thinking this must be an incorrect mod_jk setup problem.

Any help would be greatly appreciated!!!

My configuration:
apache-tomcat-6.0.20
Apache/2.2.10
mod_jk

Apache Web server - related:
File: httpd.conf
--------------------
### Global Environment ######################################################
#
# The directives in this section affect the overall operation of Apache,
# such as the number of concurrent requests.

# run under this user/group id
Include /etc/apache2/uid.conf

# - how many server processes to start (server pool regulation)
# - usage of KeepAlive
Include /etc/apache2/server-tuning.conf

# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
# container, error messages relating to that virtual host will be
# logged here. If you *do* define an error logfile for a <VirtualHost>
# container, that host's errors will be logged there and not here.
ErrorLog /var/log/apache2/error_log

# generated from APACHE_MODULES in /etc/sysconfig/apache2
Include /etc/apache2/sysconfig.d/loadmodule.conf

# IP addresses / ports to listen on
Include /etc/apache2/listen.conf

# predefined logging formats
Include /etc/apache2/mod_log_config.conf

# generated from global settings in /etc/sysconfig/apache2
Include /etc/apache2/sysconfig.d/global.conf

# optional mod_status, mod_info
Include /etc/apache2/mod_status.conf
Include /etc/apache2/mod_info.conf

# optional cookie-based user tracking
# read the documentation before using it!!
Include /etc/apache2/mod_usertrack.conf

# configuration of server-generated directory listings
Include /etc/apache2/mod_autoindex-defaults.conf

# associate MIME types with filename extensions
TypesConfig /etc/apache2/mime.types
DefaultType text/plain
Include /etc/apache2/mod_mime-defaults.conf

# set up (customizable) error responses
Include /etc/apache2/errors.conf

# global (server-wide) SSL configuration, that is not specific to
# any virtual host
Include /etc/apache2/ssl-global.conf


# use .htaccess files for overriding,
AccessFileName .htaccess
# and never show them
<Files ~ "^\.ht">
Order allow,deny
Deny from none
</Files>


### 'Main' server configuration #############################################
#
# The directives in this section set up the values used by the 'main'
# server, which responds to any requests that aren't handled by a
# <VirtualHost> definition. These values also provide defaults for
# any <VirtualHost> containers you may define later in the file.
#
# All of these directives may appear inside <VirtualHost> containers,
# in which case these default settings will be overridden for the
# virtual host being defined.
#
Include /etc/apache2/default-server.conf


# Another way to include your own files
#
# The file below is generated from /etc/sysconfig/apache2,
# include arbitrary files as named in APACHE_CONF_INCLUDE_FILES and
# APACHE_CONF_INCLUDE_DIRS
Include /etc/apache2/sysconfig.d/include.conf


### Virtual server configuration ############################################
#
# VirtualHost: If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs-2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
Include /etc/apache2/vhosts.d/*.conf

<VirtualHost *:443>
DocumentRoot /usr/share/apache-tomcat-6.0.20/webapps
ServerName login.genetwister.eu
SSLEngine on
SSLCertificateFile /etc/apache2/certwork/login_genetwister_eu.crt
SSLCertificateKeyFile /etc/apache2/certwork/login_genetwister_eu.key

<Directory /usr/share/apache-tomcat-6.0.20/webapps >
Order Deny,Allow
Allow from All
</Directory>
</VirtualHost>

DirectoryIndex index.html index.cgi index.pl index.php index.xhtml login.zul


###############################################################################################3

Tomcat-related:
File: conf/server.xml
----------------------------------
<?xml version='1.0' encoding='utf-8'?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- Note: A "Server" is not itself a "Container", so you may not
define subcomponents such as "Valves" at this level.
Documentation at /docs/config/server.html
-->
<Server port="8005" shutdown="SHUTDOWN" debug="0">

<!-- mod_jk Apache2-Tomcat connector -->
<Listener className="org.apache.ajp.tomcat6.config.ApacheConfig"
modJK="/usr/lib64/apache2/mod_jk.so" workersConfig="/usr/share/apache-tomcat-6.0.20/conf/jk/workers.properties"/>

<!--APR library loader. Documentation at /docs/apr.html -->
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />

<!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
<Listener className="org.apache.catalina.core.JasperListener" />

<!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html -->
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />

<!-- Global JNDI resources
Documentation at /docs/jndi-resources-howto.html
-->
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>

<!-- A "Service" is a collection of one or more "Connectors" that share
a single "Container" Note: A "Service" is not itself a "Container",
so you may not define subcomponents such as "Valves" at this level.
Documentation at /docs/config/service.html
-->
<Service name="Catalina">

<!--The connectors can use a shared executor, you can define one or more named thread pools-->

<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="150" minSpareThreads="4"/>


<Connector port="443" protocol="HTTP/1.1"
SSLEnabled="true"
minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" disableUploadTimeout="true"
acceptCount="100"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="/usr/share/apache-tomcat-6.0.20/conf/genetwistercert.jks"
keystorePass="password_here" />


<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />


<!-- An Engine represents the entry point (within Catalina) that processes
every request. The Engine implementation for Tomcat stand alone
analyzes the HTTP headers included with the request, and passes them
on to the appropriate Host (virtual host).
Documentation at /docs/config/engine.html -->

<!-- You should set jvmRoute to support load-balancing via AJP ie :
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
-->
<Engine name="Catalina" defaultHost="localhost" jvmRoute="worker1">

<!--For clustering, please take a look at documentation at:
/docs/cluster-howto.html (simple how to)
/docs/config/cluster.html (reference documentation) -->
<!--
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
-->

<!-- The request dumper valve dumps useful debugging information about
the request and response data received and sent by Tomcat.
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.valves.RequestDumperValve"/>
-->

<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>

<!-- Define the default virtual host
Note: XML Schema validation will not work with Xerces 2.2.
-->

<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">


<Listener className="org.apache.ajp.tomcat6.config.ApacheConfig"
append="true" forwardAll="false" modJK="/usr/lib64/apache2/mod_jk.so" workersConfig="/usr/share/apache-tomcat-6.0.20/conf/jk/workers.properties"/>

<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->

<!-- Access log processes all example.
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
-->

</Host>


</Engine>
</Service>
</Server>

conf/jk/worker.properties:
----------------------------
worker.list= worker1,jkstatus
worker.worker1.port=8009
worker.worker1.host=localhost
worker.worker.type=ajp13
worker.jkstatus.type=status


conf/jk/uriworkermap.properties:
---------------------------------------
General syntax for this file is:
# =[Worker name]

/zkSnp/=worker1
/*.zul=worker1
/*/zkau*/=worker1

#
# Except /jkManager because we need a url to jkstatus
#

/jkManager=jkstatus

#
# For no mapping the url has to start with exclamation (!)
# Usually used in static data requests. because httpd serv these is faster then Tomcat.
# So here's an EASY WAY to "Over Write" ZK's .css, .img and .js.
# you have neither CRUD zk's jar file nor editing language-addon.xml...
# you just redirect all these kind of requests to Apache Http Server!!!
#

!/img/*.jpeg=worker1
!/img/*.gif=worker1
!/img/*.jpg=worker1
!/img/*.png=worker1
!/flash/*.swf=worker1
!/activex/*.ocx=worker1
!/css/*.css=worker1
!/js/*.js=worker1

link publish delete flag offensive edit

answered 2010-04-19 12:34:45 +0800

w2davids gravatar image w2davids
15 1

bump..bump...humpty dump..anyone?

link publish delete flag offensive edit

answered 2010-04-19 15:45:39 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2010-04-19 15:45:59 +0800

I'm not at my sources, but is this correct?

worker.worker1.host=localhost
worker.worker.type=ajp13
worker.jkstatus.type=status


not be



worker.worker1.host=localhost
worker.worker1.type=ajp13
worker.jkstatus.type=status

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2006-08-17 12:43:50 +0800

Seen: 3,338 times

Last updated: Apr 19 '10

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More