LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-24-2008, 12:58 PM   #1
rtoney5
Member
 
Registered: Oct 2007
Location: FL, US
Distribution: Ubuntu MintLinux, ChromeOS, Parted Magic, PCOS OpenWorkstation, OpenSuse-11
Posts: 139

Rep: Reputation: 24
Question Example Servlets not working with Mod_JK, Apache2 Webserver& Tomcat6's Web Container


Hello:
I have Ubuntu 8.10 with Apache2, Tomcat6, MYSQL5 and Mod_JK installed. I've googled mod_jk and setup the mod_jk.conf file to the best of my ability. But when I try to use Tomcat to run servlets for my Apache2 webserver, the Servlet examples come up with the error in Red Below. When I enter http://locahost into my browser, the Default Apache index.html appears properly. Also when I enter http://localhost:8080 into my broswer, the Default Tomcat index.html comes up propery and the servlets work properly as well. I've read numerous posts out on google that say Apache can use Tomcat's Web Container to display servlets if the mod_jk package is installed an configured.

**Purpose***I'm trying to setup my own website on my pc that is accessible through the internet. I've already setup my router to forward into my internal ip address through port 80, so that's fine. I'm using DDclient with my www.dyndns.org website address (i.e. www.MyWeb.gotdns.com) Through a pc outside of my network, I can see the html pages on Apache and the htmls of the Servlet examples, but the servlets are not working.

But internally on my machine where Apache is installed, I should be able to see the tomcat servlet examples through my own Apache site on this machine (http://localhost/examples/servlets/s...loWorldExample)


http://localhost/examples/servlets/s...loWorldExample Results in the following error...:

The requested URL /examples/servlets/servlet/HelloWorldExample was not found on this server.
Apache/2.2.9 (Ubuntu) mod_jk/1.2.26 PHP/5.2.6-2ubuntu4 with Suhosin-Patch Server at localhost Port 80
 
Old 12-24-2008, 03:08 PM   #2
vladmihaisima
Member
 
Registered: Oct 2002
Location: Delft, Netherlands
Distribution: Gentoo
Posts: 196

Rep: Reputation: 33
Maybe you could list your mod_jk.conf ? (and the other configs related to mod_jk in apache ?) I have a working configuration with virtual hosts + mod_jk + apache but maybe it's better to understand your problem rather than copy my setup.
 
Old 12-24-2008, 07:51 PM   #3
rtoney5
Member
 
Registered: Oct 2007
Location: FL, US
Distribution: Ubuntu MintLinux, ChromeOS, Parted Magic, PCOS OpenWorkstation, OpenSuse-11
Posts: 139

Original Poster
Rep: Reputation: 24
Ok here are a few of my config files. I've put the location before the contents of each file, Thanks...:

***This is in the server.xml file at /var/lib/tomcat6/conf
I commented out the Listener below because the http://localhost:8080 will not work with it active....:
<Engine name="Catalina" defaultHost="localhost" debug="0">
<!--Listener className="org.apache.jk.config.ApacheConfig" modJk="/usr/lib/apache2/modules/mod_jk.so" workersConfig="/etc/apache2/workers.properties"/-->


Here is my mod_jk.conf file... at /etc/apache2/conf.d...:
JkWorkersFile /etc/libapache2-mod-jk/workers.properties
JkMount /*.jsp ajp13
JkMount /servlet/* ajp13
Alias /examples "/usr/share/tomcat6-examples/examples"
<Directory "/usr/share/tomcat6-examples/examples">
Options Indexes FollowSymLinks
</Directory>
<Location "/examples/WEB-INF/">
#AllowOverride None
deny from all
</Location>
Alias /BookNook "/var/lib/tomcat6/webapps/BookNook"
<Directory "/var/lib/tomcat6/webapps/BookNook">
Options Indexes FollowSymLinks
</Directory>
<Location "/BookNook/WEB-INF/">
#AllowOverride None
deny from all
</Location>


Here is my worders.properties file... at /etc/libapache2-mod-jk...:
workers.tomcat_home=/var/lib/tomcat6
workers.java_home=/usr/lib/jvm/java-6-sun
ps=/
worker.list=ajp13

# Define a worker named Ajp13
worker.ajp13.port=8009
worker.ajp13.host=localhost
worker.ajp13.type=ajp13
worker.ajp13.lbfactor=1

worker.loadbalancer.type=lb
worker.loadbalancer.balanced_workers=ajp13
# Defining a worker named inprocess and of type jni
worker.inprocess.type=jni
# Additional class path components.
worker.inprocess.class_path=$(workers.tomcat_home)$(ps)server$(ps)lib$(ps)tomcat-ajp.jar - Changed this line to match location of library.
worker.inprocess.cmd_line=start
worker.inprocess.class_path=$(workers.java_home)$(ps)lib$(ps)tools.jar - This line based on something I read. (Also modified to match installation)
# Unix - Sun VM or blackdown
worker.inprocess.jvm_lib=$(workers.java_home)$(ps)jre$(ps)lib$(ps)i386$(ps)server$(ps)libjvm.so - Changed this line to match location of library.
# Setting the place for the stdout and stderr of tomcat
worker.inprocess.stdout=$(workers.tomcat_home)$(ps)logs$(ps)inprocess.stdout
worker.inprocess.stderr=$(workers.tomcat_home)$(ps)logs$(ps)inprocess.stderr

Last edited by rtoney5; 12-24-2008 at 08:02 PM.
 
Old 12-26-2008, 05:23 PM   #4
vladmihaisima
Member
 
Registered: Oct 2002
Location: Delft, Netherlands
Distribution: Gentoo
Posts: 196

Rep: Reputation: 33
Quick question: do you have the ajp13 connector in the server.xml in tomcat ?
 
Old 12-27-2008, 01:29 PM   #5
rtoney5
Member
 
Registered: Oct 2007
Location: FL, US
Distribution: Ubuntu MintLinux, ChromeOS, Parted Magic, PCOS OpenWorkstation, OpenSuse-11
Posts: 139

Original Poster
Rep: Reputation: 24
Here is the server.xml file below in /etc/tomcat6 directory...:


<?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">

<!--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" />

<!-- Couldn't get this to work properly...
Listener className="org.apache.ajp.tomcat6.config.ApacheConfig" modJk="/usr/lib/apache2/modules/mod_jk.so" /-->

<!-- 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"/>
-->


<!-- A "Connector" represents an endpoint by which requests are received
and responses are returned. Documentation at :
Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
Java AJP Connector: /docs/config/ajp.html
APR (HTTP/AJP) Connector: /docs/apr.html
Define a non-SSL HTTP/1.1 Connector on port 8080
-->
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<!-- A "Connector" using the shared thread pool-->
<!--
<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
-->
<!-- Define a SSL HTTP/1.1 Connector on port 8443
This connector uses the JSSE configuration, when using APR, the
connector should be using the OpenSSL style configuration
described in the APR documentation -->
<!--
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />
-->

<!-- 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" debug="0">
<!--Listener className="org.apache.jk.config.ApacheConfig" modJk="/usr/lib/apache2/modules/mod_jk.so" workersConfig="/etc/apache2/workers.properties"/-->
<!-- Listener className="org.apache.jk.config.ApacheConfig" modJk="/path/to/mod_jk.so" / -->

<!--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">

<!-- Couldn't get this to work properly...
Listener className="org.apache.ajp.tomcat6.config.ApacheConfig" append="true" forwardAll="false" modJk="/usr/lib/apache2/modules/mod_jk.so" /-->

<!-- 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>
 
Old 12-28-2008, 04:40 AM   #6
vladmihaisima
Member
 
Registered: Oct 2002
Location: Delft, Netherlands
Distribution: Gentoo
Posts: 196

Rep: Reputation: 33
Ok, I think I have spotted the problem:

Code:
JkMount /*.jsp ajp13
JkMount /servlet/* ajp13
So, if you try to access http://localhost/examples/servlets/s...loWorldExample this will not be served by Tomcat, but by Apache.

Question: why do you need Apache ? Tomcat can run on the 80 port and deliver also HTML. If it is for a home site I think Tomcat will manage very well. So, in case you do not really need Apache I would suggest to modify the HTTP connector of Tomcat from 8080 to 80, stop Apache and you have just one server running... problem solved

Apache + Tomcat is needed for example if you need also php, or multiple Tomcat servers (because of variuous java/tomcat versions requirements for different applications) or you care a lot about performance (even though I didn't tested how much faster is Apache for HTML compared to Tomcat).

If you want to make it work as it is you could add something like "JkMount /* ajp13", but if you do not Apache at nothing else .... (or add a lot of JkMount-s for every dir, but again, using just Tomcat can be easiear)
 
Old 12-28-2008, 07:57 PM   #7
rtoney5
Member
 
Registered: Oct 2007
Location: FL, US
Distribution: Ubuntu MintLinux, ChromeOS, Parted Magic, PCOS OpenWorkstation, OpenSuse-11
Posts: 139

Original Poster
Rep: Reputation: 24
Hello. Thanks for looking into this, but i'm not sure what you are saying is the problem with the code you highlighted:

JkMount /*.jsp ajp13
JkMount /servlet/* ajp13

It seems you want me to just not use Apache and change the Tomcat port to 80. But the purpose of my post is to get Tomcat and Apache to work together as the online docs say they can. Do you have Apache2,Tomcat6 and mod_jk working on your system? If so are you using Ubuntu or another distro? I plan to use Apache more in the future and wanted to get the servlet container working to serve the pages properly. Perhaps you can post your server.xml, mod_jk.conf and workers.properties files so I can get a better idea of what I may be missing in my configuration.
Thanks again.
 
Old 12-29-2008, 07:50 AM   #8
vladmihaisima
Member
 
Registered: Oct 2002
Location: Delft, Netherlands
Distribution: Gentoo
Posts: 196

Rep: Reputation: 33
Ok, your choice if you want to use Apache + Tomcat.

If will try to explain again the problem.

The JkMount lines instruct what URL-s are served by Tomcat (through the ajp connector). So in your case all the URL-s ending in ".jsp" and all URL starting with "/servlet/" will be served by Tomcat.

The URL which you tested doesn't start with servlet and doesn't end with jsp, so it will not be served by Tomcat.

For my case I had fore some virtual hosts something like "JkMount * ajp13", while for other virtual hosts I served html/php/etc. To test if this is the problem try to put "JkMount * ajp13". This is not exactly what you want as with this line Tomcat will serve everything, but you will know your setup is working. Then you can start refining the JkMount
 
Old 12-30-2008, 08:56 PM   #9
rtoney5
Member
 
Registered: Oct 2007
Location: FL, US
Distribution: Ubuntu MintLinux, ChromeOS, Parted Magic, PCOS OpenWorkstation, OpenSuse-11
Posts: 139

Original Poster
Rep: Reputation: 24
Ok tried putting /* and *. I receive an error message using on an *. And when using the /*, it still doesn't work when I try to pull up http://localhost/examples to test any servlets.

Thanks for your help, but i'm officially giving up on this one. Too many moving parts for something so simple.
 
Old 01-07-2009, 04:44 AM   #10
cubo
LQ Newbie
 
Registered: Jan 2009
Posts: 3

Rep: Reputation: 1
I had a lot of problems too.

make sure your sites-enabled default file has the JkMount with the ajp worker name (its defined in workers.properties file on apache2 home)

eg.

JkMount /* ajp13
JkMount /examples/* ajp13
 
Old 01-07-2009, 04:49 AM   #11
cubo
LQ Newbie
 
Registered: Jan 2009
Posts: 3

Rep: Reputation: 1
Check out this link > http://tomcat.apache.org/connectors-...wto/quick.html

after doing the setup, dont forget to restart the APACHE ( sudo /etc/init.d/apache2 restart )


hereś my setup


file: /etc/apache2/worker.properties
------------------------------------------------
workers.tomcat_home=/var/lib/tomcat/
workers.java_home=/usr/local/java/
ps=/
worker.list=ajp13
worker.default.port=8009
worker.default.host=localhost
worker.default.type=ajp13
worker.default.lbfactor=1



file: /etc/apache2/mods-available/jk.load
-------------------------------------------------
LoadModule jk_module /usr/lib/apache2/modules/mod_jk.so

JkWorkersFile /etc/apache2/workers.properties
JkLogFile /var/log/apache2/jk.log
JkLogLevel info
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories -ForwardLocalAddress
JkRequestLogFormat "%w %V %T"
JkMount /* ajp13


file: /etc/apache2/sites-available/default
---------------------------------------------------------
<VirtualHost *:80>
ServerAdmin webmaster@localhost

DocumentRoot /var/www/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>

ErrorLog /var/log/apache2/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/access.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>

JkMount /* ajp13
JkMount /examples/* ajp13

</VirtualHost>




file: /etc/hosts
---------------------------------------------------------
127.0.0.1 localhost
127.0.0.1 PCNAME
192.168.2.101 PCNAME

Last edited by cubo; 01-07-2009 at 04:59 AM.
 
Old 01-07-2009, 08:36 PM   #12
rtoney5
Member
 
Registered: Oct 2007
Location: FL, US
Distribution: Ubuntu MintLinux, ChromeOS, Parted Magic, PCOS OpenWorkstation, OpenSuse-11
Posts: 139

Original Poster
Rep: Reputation: 24
Hey thanks buddy, i'll give those items you posted a try. I have to get my flat screen fixed on my other PC where the Ubuntu is on. Silly VGA wire I have to replace because the picture keeps fading in and out. On my laptop now using Puppy4-0... Good ole Puppy... I'll let you know how it turns out.
Thanks again.
 
Old 01-12-2009, 10:33 PM   #13
rtoney5
Member
 
Registered: Oct 2007
Location: FL, US
Distribution: Ubuntu MintLinux, ChromeOS, Parted Magic, PCOS OpenWorkstation, OpenSuse-11
Posts: 139

Original Poster
Rep: Reputation: 24
Thumbs up APACHE2, TOMCAT6 AND MOD_JK Mystery SOLVED!!!!

Hey Buddy it worked!! :-D))

Other than directories on tomcat_home and java_home, I was able to get the http://localhost/examples to run servlets and jsps on Apache!!!

Here was my problem...: (Substitute the /examples/* with whatever other site you want to serve (i.e. for me it was /BookNook/* ajp13


file: /etc/apache2/sites-available/default
(I just put what was missing at the end of this file for brevity)
JkMount /* ajp13
JkMount /examples/* ajp13
</VirtualHost>

****ALSO the lines below in bold red were not in the file at all.**

file: /etc/apache2/mods-available/jk.load
-------------------------------------------------
LoadModule jk_module /usr/lib/apache2/modules/mod_jk.so

JkWorkersFile /etc/apache2/workers.properties
JkLogFile /var/log/apache2/jk.log
JkLogLevel info
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories -ForwardLocalAddress
JkRequestLogFormat "%w %V %T"
JkMount /* ajp13


Thanks again buddy. At least now I have the foundation working properly.
 
Old 01-14-2009, 06:19 AM   #14
cubo
LQ Newbie
 
Registered: Jan 2009
Posts: 3

Rep: Reputation: 1
glad it helped
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Pure servlets: Designing Web UIs for Simplicity LXer Syndicated Linux News 0 03-29-2007 03:16 AM
Apache2, MySQL & PHP Web Server. FTP Needed! Bobson Linux - Networking 4 02-07-2005 04:25 PM
Apache1 & Apache2 - How do I get them both working on the same box? neocookie Linux - Software 3 09-24-2004 02:58 AM
how do i set up a webserver using mandrake 10 to use java servlets almvtb Mandriva 0 06-29-2004 03:21 PM
Connecting Apache2 with Tomcat5 using mod_jk royb Linux - Software 6 03-09-2004 06:26 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration