• Apache Tomcat - Are you looking to setup JSPWiki on Apache Tomcat?

Apache Setup#

The instructions below assume you have basic knowledge of setting up apache and tomcat. At the very least, you need to know where your installations configuration files are and must be able to adjust the example paths to suit your setup.

References#

The real HOWTO's#

The kind people at the Jakarta project have documented Apache-Tomcat configuration. Select your series, follow the Documentation links, and look for "Integrating Tomcat with a web server" (3.x series) or "JK documentation" (4.x series).

Use mod_jk#

Don't bother with jserv any more. Just use the mod_jk Apache module. Each Tomcat series has a section on setting mod_jk up; make sure you pick the version you're running to avoid complications.

Another option would be mod_webapp, but we haven't tested that for now. (Do add your remarks below if you have!)

Apache 1.3.x and Tomcat 3.2.x#

A configuration we've tested JSPWiki on uses Ajp12 with Tomcat 3.2.x, Apache 1.3.x and mod_jk. In apache's httpd.conf add the following line at the very end:

    Include /p/web/tomcat/current/conf/mod_jk.conf.local

This is the relevant snippet from mod_jk.conf.local:

#
# The following line makes apache aware of the location of the /JSPWiki context
#
Alias /JSPWiki "/p/web/tomcat/current/webapps/JSPWiki"
<Directory "/p/web/tomcat/current/webapps/JSPWiki">
    Options Indexes FollowSymLinks
    allow from all
</Directory>

#
# The following line mounts all JSP files and RPC2 uri to tomcat
#
JkMount /JSPWiki/*.jsp ajp12
JkMount /JSPWiki/ ajp12
JkMount /JSPWiki/RPC2/* ajp12

#
# The following line prohibits users from directly accessing WEB-INF
#
<Location "/JSPWiki/WEB-INF/">
    AllowOverride None
    deny from all
</Location>

#
# The following line prohibits users from directly accessing META-INF
#
<Location "/JSPWiki/META-INF/">
    AllowOverride None
    deny from all
</Location>

And this is what we have in Tomcat's server.xml:

       <!-- Apache AJP12 support. This is also used to shut down tomcat.
          -->
        <Connector className="org.apache.tomcat.service.PoolTcpConnector">
            <Parameter name="handler"
           value="org.apache.tomcat.service.connector.Ajp12ConnectionHandler"/>
            <Parameter name="port" value="8007"/>
        </Connector>

Apache 1.3.x and Tomcat 4.1.x#

We are currently running JSPWiki with apache 1.3.26, Tomcat 4.1.18, and mod_jk using ajp13.

In apache's httpd.conf, add the following line at the very end:

    Include /p/web/tomcat/current/conf/mod_jk.conf.local

See mod_jk.conf.tomcat4_example(info) for the contents of the configuration file.

Mod_jk requires a workers.properties file; see workers.properties.tomcat4_example(info) for a simple, functional one that only uses ajp13.

Finally, tomcat's server.xml needs to have AJP 1.3 defined. The default server.xml contains the following entry:

    <!-- 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"
               useURIValidationHack="false"
               protocolHandlerClassName="org.apache.jk.server.JkCoyoteHandler"/>

Notes:

  • The connection seems to be extremely picky about the mod_jk.so you use. If you get weird errors, or no errors at all, try another binary, or consider compiling your own.

Q&A#

Q: how to allow access to the Tomcat manager webapp through an Apache connection?#

How do I allow access to something like the Tomcat manager app (which is not a normal war, just a file manager.xml in the webapp directory)? The normal alias/mount directives above don't seem to work, apache says access is denied. --ebu

A: example configuration using mod_jk#

There's really nothing special about this - just that the manager webapp needs to be defined per virtual host, not globally for all virtual hosts. In short:

  • in Apache's httpd.conf, map all requests to Tomcat. (We have a VirtualHost section with accompanying JkMount /* ajp13. Yes, this is ineffective with large amounts of static content, because the AJP connection slow thing up. Tomcat fileservering is quite fast, and if you only need JSP's and Servlets, I recommend using no Apache at all.)
  • In Tomcat's server.xml, in the appropriate Host section (for the same virtual host), define a Context path="/manager" privileged="true" docBase="...path...".

You can also use just a simple

JkMount /manager/* ajp13
if you are not using virtual hosts.

--JanneJalkanen

Q: mod_jk connection timeouts[#1]#

Mod_jk seems to be producing lots of errors like this:

02-May-2003 14:04:45 org.apache.jk.common.ChannelSocket processConnection
INFO: connection timeout reached
What can I do about them?

A: not solved, see below#

Q: Leaking file handles with apache/tomcat#

Examining mysterious server crashes, I noticed that my java processes are collecting huge amounts of file handles (in linux: /proc/process_#/fd/). Eventually they eat up all memory and swap, and system load shoots sky high. What gives?

A: infinite timeouts?#

In an attempt to solve the previous problem[1], we at jspwiki.org had tried setting Tomcat's Coyote connection timeout to 0 (infinite) in the server.xml Connector tag. Result: connections really do hang infinitely, they accumulate with a steady pace, and each connection eats up n file handles. Crash and burn. Lesson: no infinite timeouts for mod_jk.

Depending on your Tomcat version, you may have experienced this problem due to a bug introduced in Tomcat 6 with the keepAliveTimeout feature in Coyote's AJP protocol. The nature of this problem was caused by Tomcat failing to close sockets after the keepAliveTimeout expired. The Tomcat sockets would remain in a CLOSE_WAIT state but the corresponding mod_jk sockets would close as normal. Since, sockets correspond directory to file descriptors, after some amount of usage and time, Tomcat would run out of available file descriptors and hang indefinitely. This bug was fixed in SVN commit r589062 and released in Tomcat 6.0.15 (http://tomcat.apache.org/tomcat-6.0-doc/changelog.html Harmonize with HTTP java.io code. Otherwise the socket is not closed.). -- Eric Young


Q: I am having trouble with Attachments (not mentioned in the FAQ) after touching the Wiki in Tomcat manager app.?#

I always running into the same problem after I restarted Tomcat or just reloaded the JSPWiki context in Tomcat 4.1.27. The error I get is always only concering the attachment functionality:

The requested URL /JSPWiki/attach was not found on this server.
If I remove the JSPWiki context (from within the Tomcat manager app) and redeploy it completely it works fine up to the next restart of Tomcat or reloading of the context. --RaimundKammering

A - Solved it by myself: The problem seems to be the interplay of Apache http and Tomcat (via Jk2 connector). If I'am using the explicit port number to talk to tomcat directly the problem dosn't appear. So it seems like the Jk2 connector is automaticly deploy the URI "JSPWiki/attach" on the first installation of JSPWiki, but didn't recognice a change (aka reload of context or tomcat restart). I will play around with adding some Jk mounts to Apache to see if I can find a workaround for this problem.

Comment: Yes a Jk mount statement of the form:
JkMount /JSPWiki/* ajp13:<myserver>:8009
and a worker:
[uri:/JSPWiki/*]
worker=ajp13:<myserver>:8009
fixed the problem. Should this go to the FAQ?

Q: How to stop people from stealing bandwidth by linking to my attached images?#

A: Blocking image inlining

Q: Performance issues under mod_jk 1.2.8 and tomcat 5.0.28#

Has anyone experienced performance problems with pages > 8k proxied through mod_jk 1.2.8+tomcat 5.0.28? A browser will "hang" while attempting to get a large page (Recent Changes for example), regardless of keepalive settings. From the tomcat side it appears as if the request is completed, yet an strace of the apache (1.3 btw) process shows mod_jk blocked on a socket read. It appears that the response is being buffered somewhere and never getting to the client. This may be related to the timeout issue[#1], as setting a very low connection timeout on the Connector will cause the data to be flushed intact to the client (with an intermediate delay equal to the connection timeout setting).

Q: Using Apache 2.0.48->mod_jk 1.2->Tomcat 4.1.31 in RedHat WS 3.0 causes a memory leak that throws errors when the system starts using swap regardless of the JVM heap sizes.#

Using Tomcat 4.1.31 Apache 2.0.48 on a RedHat WS 3.0 box produces a consistant memory leak. When the physical memory is exhausted and it starts to hit swap tomcat starts throwing java.lang.OutOfMemory errors regardless of the JVM heap size allocated. Testing has been done with optimizeit and shows the leak is consistant even when no web applications are loaded. Testing has also been done against Tomcat 4.1.30 with Apache 2.0.41 and combinations of tomcat/apache.

A: 'not solved'


I have the same problem with Tomcat 5.0.28, mod_jk 1.2.8 and Apache 1.3.33 on Mac OS X 10.3.7. How do I fix it?

Thanks.


Q: Problem with UTF-8 and Tomcat 5.5?#

Set useBodyEncodingForURI="true" in the connector you are using. For example, your connector could look like this:

<Connector port="8009" className="org.apache.coyote.tomcat4.CoyoteConnector"                   
           enableLookups="false" redirectPort="8443" protocol="AJP/1.3" 
           connectionTimeOut="120000" acceptCount="100" maxThreads="250"
           minSpareThreads="25" maxSpareThreads="75" 
           useBodyEncodingForURI="true">


By the terms of this site I'm a "Mere Mortal". This article comes close to my current problem but doesn't discuss the Mac OS X platform (I'm running an Xserve). And it doesn't appear to tell how to test what's already installed and what version. That would be useful. Given this is a Mac it's possible the default install has already added Tomcat and mod_jk, and if so, which version. Don't know.

My specific situation is I have Servoy installed, a java-based frontend to SQL (http://www.servoy.com) which I believe uses Tomcat. My consultant has created a JSP to work with the website (pick up fields from a web form and create new records in the SQL database via Servoy). This has been successfully tested in his Windows environment but he has no knowledge of Macs (and I'm a mere mortal). ;-)

The submit button works in Windows (not sure whether that's under Apache or not) but on the Xserve a click of the submit button results in "Method Not Allowed. The requested method POST is not allowed for the URL /CreateSession.jsp. Apache/1.3.33 Server at www.website.com Port 16080."

My search for an effective solution has lead me here. I'd appreciate whatever elightenment might be provided.

Kind regards

--Morley Chalmers, 22-May-2006

Apache 2.0 and Tomcat 5.5#

I found the following way to configure Apache connector to JSPWIKI deployed under Tomcat.

Append the following section Apache's conf/httpd.conf :

ProxyPass        /wiki/ http://localhost:8081/wiki/
ProxyPassReverse /wiki/ http://localhost:8081/wiki/ 

And the following section should added to Tomcat's conf/server.xml:

<Connector port="8081" proxyPort="80" proxyName="www.yourdomain.com">

(see http://tomcat.apache.org/tomcat-6.0-doc/proxy-howto.html)

Note: if your apache connector is https but the tomcat is http, you also need scheme="https"

Virtual Hosts#

It may happen that Proxying seems to work but that "Preview" button (or submitting attachments to a page) does not. This is because session is lost between transactions and a new session is started each time. It seems that this happens mostly when virtual hosting is used.

Two solutions exist:

  1. Tomcat is configured to remove application path in front of sessions' cookies
  2. Apache is configured to recode cookies' paths (ProxyPassReverseCookiePath and ProxyPassReverseCookieDomain Directives)

I tested the first one. Just modify Connector parameters in Tomcat conf\server.xml to add emptySessionPath="true". For example:

    <Connector port="8080"
               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" redirectPort="8443" acceptCount="100"
               debug="0" connectionTimeout="20000" 
               disableUploadTimeout="true" 
               proxyName="www.your-domain.com"
               proxyPort="80"
               emptySessionPath="true"
               URIEncoding="UTF-8"/> 
ChristopheDupriez

HTTPS#

In our deployment we require authenticated access over HTTPS, so the our settings are a bit more complex:

httpd.conf:


SSLProxyEngine on

<Location  /wiki/>
    Order allow,deny
    Allow from all
    AuthType Basic
	AuthName "Username and Password Required to access WIKI"
	AuthUserFile "..... path-to-auth-file ...."
	Require valid-user
	SSLRequireSSL
</Location>

ProxyPass        /wiki/ https://localhost:8443/wiki/
ProxyPassReverse /wiki/ https://localhost:8433/wiki/ 


server.xml:

<Connector port="8443" proxyPort="443" proxyName="www.yourdomain.com"  maxHttpHeaderSize="8192"
               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" disableUploadTimeout="true"
               acceptCount="100" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" />
               

-- Andy Malakov

Add new attachment

Only authorized users are allowed to upload new attachments.

List of attachments

Kind Attachment Name Size Version Date Modified Author Change note
tomcat4_example
mod_jk.conf.tomcat4_example 3.0 kB 1 10-Jan-2003 13:22 Ebu
tomcat4_example
workers.properties.tomcat4_exa... 0.4 kB 1 11-Jan-2003 02:59 62.142.13.212
« This page (revision-45) was last changed on 22-Sep-2010 21:12 by 194.105.97.90