Solved

Connect Tomcat With Apache

Posted on 2011-03-07
11
1,125 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
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

Technology Partners: 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!

Question has a verified solution.

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

Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

759 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