Solved

Connect Tomcat With Apache

Posted on 2011-03-07
11
1,122 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

735 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