Apache2 & Tomcat6 - mod_jk problem.

Hi

I have a strange problem related to the mod_jk module on OpenSuse 11.2. X64.

I have apache2 (of the distribution) working stanad alone. With standard installation dir.
I have tomcat6 (of the distribution) working stand alone. With standard installation dir.

IN ADDITION I HAVE:
Netbeans 6.5 with Tomcat 6.0.18 under /usr/local/Netbeans6.5rc2 & /usr/local/apache-tomcat-8.0.18 which is not active while tomcat6 is running. If I want to develop with Netbeans I stop tomcat6, & start tomcat from Netbeans (thus running the development version of tomcat) & it works fine. HOWEVER - the tomcat installations share webapps directory, implemented as a softlink: /usr/share/tomcat6/webapps -> /usr/local/apache-tomcat-6.0.18/webapps.

I have discovered that the documentation on mod_jk is for tomcat5 & that is not working at all.

This is where I am at…
I have the mod_jk working from local host (on some of the webapplications), but not from remote browsers. However the directory listing on each application (that runs on localhost fine) shows up from remote browsers

TOMCAT
I have these two files in tomcat (/usr/share/tomcat6/)conf/jk directory: mod_jk.conf & workers.properties

I have these two lines in server.xml
<Connector port=“8009” protocol=“AJP/1.3” redirectPort=“8443” />

<Listener className=“org.apache.jk.config.ApacheConfig” append=“true” jkWorker=“ajp13” />

These lines enable the tomcat to write a file conf/auto/mod_jk.conf on startup (which have to be accesable to everybody or the tomcat will not start).

APACHE

All my local additions to httpd is done in a file /etc/apache2/httpd.conf.local which is included by httpd.conf. Easy.

httpd.conf.local has these three lines:
Include /usr/share/tomcat6/conf/jk/mod_jk.conf
Include /usr/share/tomcat6/conf/auto/mod_jk.conf
JkShmFile /tmp/apache2.shm


The conf/jk/mod_jk.conf has this content:

simple configuration for apache (for AJP connector, modul mod_jk.so)

<IfModule mod_jk.c>

JkWorkersFile /usr/share/tomcat6/conf/jk/workers.properties
JkLogFile /var/log/tomcat6/mod_jk.log

# Log level to be used by mod_jk
JkLogLevel error

# The following line makes apache aware of the location of
# the /servlet-examples context
Alias /examples "/srv/tomcat6/webapps/examples"
&lt;Directory "/srv/tomcat6/webapps/examples"&gt;
    Options Indexes FollowSymLinks
    allow from all
&lt;/Directory&gt;

# The following line makes apache aware of the location of
# the /manager context
Alias /manager "/srv/tomcat6/webapps/manager"
&lt;Directory "/srv/tomcat6/webapps/manager"&gt;
    Options All
    allow from all
&lt;/Directory&gt;


# The following line makes apache aware of the location of
# the /MyApp context
Alias /Myapp "/srv/tomcat6/webapps/MyApp"
&lt;Directory "/srv/tomcat6/webapps/MyApp"&gt;
    Options Indexes FollowSymLinks
    allow from all
&lt;/Directory&gt;

&lt;Location "/srv/tomcat6/webapps/MyApp/WEB-INF/"&gt;
    AllowOverride None
    deny from all
&lt;/Location&gt;

</IfModule>


The auto/mod_jk.conf (written by tomcat) has this content:
########## Auto generated on Sun Dec 13 11:12:58 CET 2009##########

<IfModule !mod_jk.c>
LoadModule jk_module “/usr/lib64/apache2/mod_jk.so”
</IfModule>

<VirtualHost localhost>
ServerName localhost

JkMount /manager ajp13
JkMount /manager/* ajp13

JkMount /docs ajp13
JkMount /docs/* ajp13

JkMount /examples ajp13
JkMount /examples/* ajp13

JkMount /MyApp ajp13
JkMount /MyApp/* ajp13

JkMount /host-manager ajp13
JkMount /host-manager/* ajp13

</VirtualHost>


Content of the workers.properties file:

Add ‘inprocess’ if you want JNI connector

worker.list=ajp12, ajp13

, inprocess

#------ DEFAULT ajp12 WORKER DEFINITION ------------------------------
#---------------------------------------------------------------------

Defining a worker named ajp12 and of type ajp12

Note that the name and the type do not have to match.

worker.ajp12.port=8007
worker.ajp12.host=localhost
worker.ajp12.type=ajp12

Specifies the load balance factor when used with

a load balancing worker.

Note:

----> lbfactor must be > 0

----> Low lbfactor means less work done by the worker.

worker.ajp12.lbfactor=1

#------ DEFAULT ajp13 WORKER DEFINITION ------------------------------
#---------------------------------------------------------------------

Defining a worker named ajp13 and of type ajp13

Note that the name and the type do not have to match.

worker.ajp13.port=8009
worker.ajp13.host=localhost
worker.ajp13.type=ajp13

Specifies the load balance factor when used with

a load balancing worker.

Note:

----> lbfactor must be > 0

----> Low lbfactor means less work done by the worker.

worker.ajp13.lbfactor=1


Any idea on what is going on here? Really need to get this working in a safe manner.

Kind Regards
Oddvard Myrnes

I am not an expert on this but I have a very simple working set up at one of my sites.

In tomcat, there is nothing special other than the following line in server.xml enabled (It was enabled in the default installation itself so that JK can come on port 8009):

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

In apache2, we need to enable the “jk” module. It is easy, just add that module name inside the APACHE_MODULES variable in file /etc/sysconfig/apache2.

APACHE_MODULES="... jk"

“jk” requires configuration. Let us store it in /etc/apache2/tomcat.conf. This file name needs to be specified in /etc/sysconfig/apache2 in variable APACHE_CONF_INCLUDE_FILES

APACHE_CONF_INCLUDE_FILES="tomcat.conf"

Content of /etc/apache2/tomcat.conf (example). Adjust the JkMount as per your need.

JkWorkersFile   /etc/apache2/worker.properties
JkLogFile       /var/log/apache2/mod_jk.log
JkShmFile       /var/log/apache2/jk-runtime-status
JkMount         /nano*          nanoserver
JkMount         /manager*       nanoserver

Now edit the worker properties file to reflect the above:
/etc/apache2/worker.properties

worker.list=nanoserver

worker.nanoserver.type=ajp13
worker.nanoserver.host=localhost
worker.nanoserver.port=8009

That’s it. So, we didn’t touch any files in the installation directories.

Hi,

The problem I have is that it works only when I access Apache/tomcat from a browser on localhost (the one running both apache & tomcat). If I access the Apache/tomcat from another machine, it reply with an error & the Apache log file says it can not find the file. It is purely an access problem. All requests for tomcat applications are forwarded when the request comes from localhost (except tomcat manager, host-manager), but not from a remote machine. Any idea?

Oddvard

That’s not surprising, you’ve put the JKMount lines inside a <VirtualHost localhost> scope.

Hi there,

Oootch…Yes, that made one problem go away. Thanks…:shame:

There is still a problem though, I can’t get the manager & host-manager applications working. It gives a 404 error & nothing is recorded in apache error.log not in tomcat6 catalina.out. Any idea?

Oddvard

Hi,

My problem was cleared when I reinstalled tomcat & added a Admin user to the tomcat-users.xml file. It is now fixed. Thank you all for your kind attention :slight_smile: