Solved

Connect Tomcat With Apache

Posted on 2011-03-07
11
1,128 Views
Last Modified: 2012-05-11
On XP i've installed Apache 2.2 and two instances of Tomcat 6 to try connecting Tomcat with Apache using mod_jk along the lines in a book called 'Professional Apache Tomcat 6'.  
I have the JkMount line as /examples/jsp/*   worker1.  The problem seems to be that Apache is looking for /examples/jsp/*  under it's own /.../htdocs directory instead of under the Tomcat
/...webapps/examples directory.

From Apache error log:


[Mon Mar 07 15:40:23 2011] [notice] Child 3120: Starting thread to listen on port 80.
[Mon Mar 07 15:40:44 2011] [client 127.0.0.1] File does not exist: C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/favicon.ico
[Mon Mar 07 15:40:51 2011] [client 127.0.0.1] File does not exist: C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/examples
[Mon Mar 07 15:40:51 2011] [client 127.0.0.1] File does not exist: C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/favicon.ico
0
Comment
Question by:xoxomos
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 3
11 Comments
 

Author Comment

by:xoxomos
ID: 35063304
What entry makes Apache look into the Tomcat directories for /examples/jsp/* instead of looking in the Apache directories?
0
 
LVL 92

Expert Comment

by:objects
ID: 35063476
> The problem seems to be that Apache is looking for /examples/jsp/*  under it's own /.../htdocs directory instead of under the Tomcat
/...webapps/examples directory.

apache doesn't look in tomcats directory.
your problem is because the incoming requests do not match /examples/jsp/* so are being handled by apache (and not tomcat)
0
 

Author Comment

by:xoxomos
ID: 35065097
This is the place i'm trying to get to:

"A Tomcat worker is a Tomcat instance that is waiting to execute servlets on behalf of some web server. For example, we can have a web server such as Apache forwarding servlet requests to a Tomcat process (the worker) running behind it.
and the reason:
"We want to provide load balancing, meaning run multiple Tomcat workers each on a machine of its own and distribute the requests between them."
http://tomcat.apache.org/connectors-doc-archive/jk2/jk/workershowto.html

I thought information in the workers.properties file in Apache's conf directory did that forwarding.
No??
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 92

Expert Comment

by:objects
ID: 35065236
Apache forwards the request onto Tomcat and lets tomcat handle it. Once it has forwarded the request apache does nothing more with it.
So if you'rre getting errors in Apache then they are for requests that are not being forwarded to tomcat.
check your access logs to see the request being received by apache
0
 

Author Comment

by:xoxomos
ID: 35065730
Right, that's what is happening.


127.0.0.1 - - [07/Mar/2011:20:23:02 -0800] "GET /favicon.ico HTTP/1.1" 404 209
127.0.0.1 - - [07/Mar/2011:20:33:22 -0800] "GET /favicon.ico HTTP/1.1" 404 209
127.0.0.1 - - [07/Mar/2011:20:33:40 -0800] "GET /examples/jsp/ HTTP/1.1" 503 323
127.0.0.1 - - [07/Mar/2011:20:33:42 -0800] "GET /favicon.ico HTTP/1.1" 404 209
127.0.0.1 - - [07/Mar/2011:20:33:52 -0800] "GET /examples/jsp/ HTTP/1.1" 503 323
127.0.0.1 - - [07/Mar/2011:20:33:54 -0800] "GET /favicon.ico HTTP/1.1" 404 209
127.0.0.1 - - [07/Mar/2011:20:34:14 -0800] "GET /examples/jsp/* HTTP/1.1" 503 323
127.0.0.1 - - [07/Mar/2011:20:34:17 -0800] "GET /favicon.ico HTTP/1.1" 404 209
I'm putting in http://localhost/examples/jsp believing something i've put in the http.conf and in the ../modules directory will direct to Tomcat.

# http://tomcat.apache.org/connectors-doc/generic_howto/quick.html
# Define 1 real worker using ajp13
  worker.list=worker1
  # Set properties for worker1 (ajp13)
  worker.worker1.type=ajp13
  worker.worker1.host=127.0.0.1
  worker.worker1.port=8009
 
0
 
LVL 92

Accepted Solution

by:
objects earned 300 total points
ID: 35065861
> 127.0.0.1 - - [07/Mar/2011:20:33:42 -0800] "GET /favicon.ico HTTP/1.1" 404 209

Doesn't match /examples/jsp/* so is handled by apache

> 127.0.0.1 - - [07/Mar/2011:20:33:52 -0800] "GET /examples/jsp/ HTTP/1.1" 503 323

503 suggests that theres a problem with your connection to tomcat, or tomcat isn't running
0
 

Author Comment

by:xoxomos
ID: 35071766
I added some lines i googled into the httpd.conf and it does seem to be headed in the right direction.  Now at least the message is coming back from Tomcat rather than Apache.


<IfModule jk_module>
     JkWorkersFile conf/workers.properties
     JkLogFile logs/mod_jk.log
     JkLogStampFormat "[%b %d %Y - %H:%M:%S] "
     JkRequestLogFormat "%w %V %T"
     JkLogLevel info
 
     JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
 
     Alias /tomcat-demo "F:/Tomcat/tomcat6a/apache-tomcat-6.0.32/webapps/examples/jsp/"
 
     <Directory "F:/Tomcat/tomcat6a/apache-tomcat-6.0.32/webapps/examples/jsp/">
         AllowOverride None
         Allow from all
     </Directory>
 
     <Location /*/WEB-INF/*>
         deny from all
     </Location>
 
     JkMount /tomcat-demo/* worker1
 
</IfModule>



And the message comes back from Tomcat as it has picked up the correct version.

HTTP Status 404 - /tomcat-demo/

type Status report

message /tomcat-demo/

description The requested resource (/tomcat-demo/) is not available.

Apache Tomcat/6.0.32
0
 

Author Comment

by:xoxomos
ID: 35072677
Almost there :-)
The last change was the JkMount /examples/jsp/* worker1 in the httpd.conf file.
It's now pulling up the jsp examples page from the Tomcat install.

 LoadModule  jk_module modules/mod_jk-1.2.31.dll
 <IfModule jk_module>
     JkWorkersFile conf/workers.properties
     JkLogFile logs/mod_jk.log
     JkLogStampFormat "[%b %d %Y - %H:%M:%S] "
     JkRequestLogFormat "%w %V %T"
     JkLogLevel info
 
     JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
 
     Alias /tomcat6a "F:/Tomcat/tomcat6a/apache-tomcat-6.0.32/webapps/examples/jsp"
 
     <Directory "F:/Tomcat/tomcat6a/apache-tomcat-6.0.32/webapps/examples/jsp/*">
         AllowOverride None
         Allow from all
     </Directory>
 
     <Location /*/WEB-INF/*>
         deny from all
     </Location>
 
     JkMount /examples/jsp/* worker1
 
</IfModule>
 
0
 

Author Comment

by:xoxomos
ID: 35073010
Oh yes, and I needed to change Document root.
0
 

Author Comment

by:xoxomos
ID: 35077572
From what I can tell, I needed this alias to send from Apaches directories to Tomcats.

 Alias /tomcat6a "F:/Tomcat/tomcat6a/apache-tomcat-6.0.32/webapps/examples/jsp"
 
     <Directory "F:/Tomcat/tomcat6a/apache-tomcat-6.0.32/webapps/examples/jsp/*">
Now the main problem is coming back.  I get to the jsp samples in Tomcat but when I execute, the results come back not rendered.  Still shows all the html tags etc.   I think it may be some directive i need in that mod_jk, but that's another question.
Thanks.
0
 

Author Closing Comment

by:xoxomos
ID: 35077587
Actually i didn't need to do anything with Apache's Document root
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question