Solved

Connect Tomcat With Apache

Posted on 2011-03-07
11
1,115 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Forward apache log to Syslog-NG 7 82
Hosting application in Apache and Tomcat 1 102
Best IDE for PHP starters 11 122
Updating PHP in Windows Server 2012 r2 22 158
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…
If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

785 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