Solved

Connect Tomcat With Apache

Posted on 2011-03-07
11
1,103 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
  • 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
 
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now