Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Servlets and Tomcat/Apache

843835Feb 4 2003 — edited May 10 2005
Okay,

Tomcat 4.1 running with Apache.
Installed mod_jk, piece of cake.
JSPs run through Apache like a dream.
Tomcat examples ( jsp and servlets) run through Apache perfectly ( that is no :8080 business).

My JSP's run through Apache no problem. Works great.

My SERVLETS WILL NOT RUN THROUGH APACHE FOR ANYTHING.

My context looks like this in server.xml:

<Context path="/nuweb" docBase="/home/shared/nuweb" debug="0"
reloadable="true" crossContext="true">
<Logger className="org.apache.catalina.logger.FileLogger"
prefix="nuweb" suffix=".log"
timestamp="true"/>

</Context>

Note: that I am not under <TOMCAT_HOME>/webapps.

The reason is that I will, in production not be the Unix admin on the server. I will only have priviledges within my directory. I will not be able to drop war files in the webapps directory. I will not be able
to start and stop tomcat or apache ( there are 100 diffrent apache contexts on that machine and someday many of them will be going through tomcat for jsp and servlet support).

My servlets will only run if I put :8080/nuweb/servlet/HelloServlet in the URL. Take off the 8080 and I get Page not found. Not the tomcat 404 page, the Browswer 404 errror.

Here is my web.xml which lives in the WEB-INF directory of of /home/shared/nuweb

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">


<web-app>
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>org.nu.servlet.HelloServlet</servlet-class>
</servlet>


<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>


<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>

</web-app>

In devlopment I am on a system that is very close to what the production server will look like ( Tomcat 4.1 same version of Apache, same Unix ). In development I can restart all the servers edit server.xml etc. On the production I would have to schedule that stuff. I want to be able to compile classes and drop them in the WEB-INF/classes... directory and have them run. Is that too much to ask?




Comments

843835
Okay,

Found my problems with servlets. mod_jk.conf in the /etc/httpd/conf
directory needs to have JkMount stuff in it to tell Apache where the
application is.

New problem: I cannot access any .html file. ??

Tried putting the html in the WEB-INF. No luck.
Tried adding JkAutoAlias to mod_jk.conf. Got 403 for everything I tried to access. Of coures I want Apache to serv up the html and all other static content. And Tomcat to only serv up servlets and jsp. Does anybody have any ideas out there??
843835
Okay,

Tomcat 4.1 running with Apache.
Installed mod_jk, piece of cake.
JSPs run through Apache like a dream.
Tomcat examples ( jsp and servlets) run through Apache
perfectly ( that is no :8080 business).

My JSP's run through Apache no problem. Works great.

My SERVLETS WILL NOT RUN THROUGH APACHE FOR ANYTHING.

My context looks like this in server.xml:

<Context path="/nuweb" docBase="/home/shared/nuweb"
debug="0"
reloadable="true"
eloadable="true" crossContext="true">
<Logger
<Logger
gger
className="org.apache.catalina.logger.FileLogger"
prefix="nuweb" suffix=".log"
timestamp="true"/>

</Context>

Note: that I am not under <TOMCAT_HOME>/webapps.
This seems to me to be the main problem.

http://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/context.html
states:
You may specify an absolute pathname for this directory or WAR file, or a pathname that is relative to the appBase directory of the owning Host.

http://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/host.html
The Application Base directory for this virtual host. This is the pathname of a directory that may contain web applications to be deployed on this virtual host. You may specify an absolute pathname for this directory, or a pathname that is relative to the $CATALINA_HOME directory. See Automatic Application Deployment for more information on automatic recognition and deployment of web applications to be deployed automatically.

If you Catalina_Home is "/var/tomcat4" you could try
docBase="../../home/shared/nuweb/".

If this does not work, i belief only symbolik linkes will work like
/var/tomcat/virthosts/home --> /home
Because now you can access it via
docBase="virthosts/home/shared/nuweb/".


843835
Yeah,

Symbolic links work okay. Made a link from where the jsp, servlet and html code lives to /var/tomcat4/webapps/nuweb. This link works great for jsp and servlets. After changing that mod_jk.conf to make apache "aware" of /var/tomat4/webapps/nuweb servlets and jsp under this link worked great but I lost the ablility to access any sort of static html file. Even if I put it in the WEB-INF directory. It has got to be somthing with those JkMount or JkAlias

Tomcat doc states:

http://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/jk.html

Configuring Apache to serve static web application files

If the Tomcat Host appBase (webapps) directory is accessible by the Apache web server, Apache can be configured to serve web application context directory static files instead of passing the request to Tomcat.

Caution: If Apache is configured to serve static pages for a web application it bypasses any security contraints you may have configured in your web application web.xml config file.

Use Apache's Alias directive to map a single web application context directory into Apache's document space for a VirtualHost:

# Static files in the examples webapp are served by apache
Alias /examples /export/home/web/host1/webapps/examples

JkMount /*.jsp ajp13
JkMount /*/servlet/ ajp13


Use the mod_jk JkAutoAlias (Apache 1.3 only) directive to map all web application context directories into Apache's document space. Attempts to access the WEB-INF or META-INF directories within a web application context or a Web Archive *.war within the Tomcat Host appBase (webapps) directory will fail with an HTTP 403, Access Forbidden.

Example configuration for an Apache VirtualHost:

# Static files in all Tomcat webapp context directories are served by apache
JkAutoAlias /export/home/web/host2/webapps

JkMount /*.jsp ajp13
JkMount /*/servlet/ ajp13

Mine looks like:


Alias /nuweb /var/tomcat4/webapps/nuweb < this is a symbolic like to /home/shared/nuweb where WEB-INF/blah lives

JkMount /nuweb/*.jsp ajp13
JkMount /nuweb/servlet/ ajp13



843835
Okay,

Finally found the problem.

mod_jk.conf must have the Alias directive to inform Apache about the static content for the instance. Something like:

Alias /nuweb /var/tomcat4/webapps/nuweb

Where the /var/tomcat4/webapps/nuweb is really a symbolic link from
/var/tomcat4/webapps/nuweb to /home/shared/nuweb

The after this I was getting HTTP 403 errors. The final piece of the
puzzle was the permissions on that symbolic link. Changed them to 755
and everything started working.

843835
Hi. I hope you can help me.

I saw this tutorial http://www.sitepoint.com/article/305/7 in order to integrate Tomcat and Apache (so I'm using 'jakarta-tomcat-4.1.18-LE-jdk14.zip' and 'apache_2.0.44-win32-x86-no_ssl.msi' versions).
I followed every point, and everything worked fine until the end :(
The problem is that if I request the server examples via http://serverHost:8080/examples/jsp I have no problem at all but, if I request the server examples via http://serverHost/examples/jsp I see the examples but, when I click the .jsp I see only text instead of dynamic content!!

As I said, I check all the points in the tutorial configuration and I don't understand what's going on.

The mod_jk.conf is generated automatically by Tomcat in directory ../conf/auto so it looks like:
########## Auto generated on Tue Mar 18 11:39:28 VET 2003##########
<IfModule !mod_jk.c>
  LoadModule jk_module d:/Apache/Apache2/modules/mod_jk.dll
</IfModule>

JkWorkersFile "d:/Apache/Tomcat/conf/jk/workers.properties"
JkLogFile "d:/Apache/Tomcat/logs/mod_jk.log"

JkLogLevel info

<VirtualHost localhost>
    ServerName localhost

    JkMount /admin ajp13
    JkMount /admin/* ajp13

    JkMount /webdav ajp13
    JkMount /webdav/* ajp13

    JkMount /examples ajp13
    JkMount /examples/* ajp13

    JkMount /tomcat-docs ajp13
    JkMount /tomcat-docs/* ajp13

    JkMount /manager ajp13
    JkMount /manager/* ajp13
</VirtualHost>
Besides, in the mod_jk.log this appears:
[Tue Mar 18 11:39:48 2003]  [jk_connect.c (203)]: jk_open_socket, connect() failed errno = 61
[Tue Mar 18 11:39:48 2003]  [jk_ajp_common.c (626)]: Error connecting to tomcat. Tomcat is probably not started or is listenning on the wrong port. Failed errno = 61
I think maybe the above message could tell something...


Please reply if you know how to solve this issue.

Thanks in advance, really
Juan Pablo
843836
Hi

I can run onlt html pages .but not able to run even JSps through Apache .But works fine from Tomcat..Getting 500 Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
843836
Hi,
I am also facing same error.
I am not able to view my servlets via apache web server.
ie when i do "http://localhost/enlighta/logon"
I get http 404 page not found error
but when I do http://localhost:8080/enlighta/logon
all works fine

I am using apache 2 and tomcat 4.5
This is I have done:

1.I have http server running on port 80
2. appserver on port 8080
3. I have a war file enlighta.war deployed on webserevr
4. The static content like images and html page I have moved to webserver
5. The servlet context of the app on the app server is /enlighta
6. In the web.xml I have defined all the servlet maping.

the port 8009 has the connecter is running/listening.

the configuration

sever.xml on tomcat
-----------------------------------------------------
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009"
enableLookups="false" redirectPort="8443" protocol="AJP/1.3" />

<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
---------------------------------------------------------------

httpd.conf on apache
---------------------------------------------------------------
# Load mod_jk
LoadModule jk_module modules/mod_jk.so

# Configure mod_jk
JkWorkersFile conf/workers.properties
JkLogFile logs/mod_jk.log
JkLogLevel info

# First Virtual Host.
<VirtualHost 192.168.1.2:8080>
ServerAdmin smittal@enlighta.com
DocumentRoot /enlighta/
ServerName localhost
ErrorLog logs/enlighta_error_log
TransferLog logs/enlighta_access_log
JkMount /enlighta/* ajp13
</VirtualHost>

workers.properties
-------------------------------------------------
worker.list=ajp13


#
# Defining a worker named ajp13w and of type ajp13
# Note that the name and the type do not have to match.
#
worker.ajp13.type=ajp13
worker.ajp13.host=localhost
worker.ajp13.port=8009
-----------------------------------------------------

Now I feel I am doing something wrong on defining virtual host.
Or may be something else is wrong.
I have gone thru the previous thread but I dont have mod_jk.conf file.

Please help!!!
Thanks
Sachin
1 - 7
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jun 7 2005
Added on Feb 4 2003
7 comments
153 views