Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Moving webapp directories? 1

Status
Not open for further replies.

ctroyp1

IS-IT--Management
Feb 7, 2006
13
US
I have a fresh install of Tomcat 5 which is successfully connected to Apache2 via ajp13/mod_jk. Everything works from the Tomcat standalone as well as linking to the example files from Apache.

I have virtual host in Apache and I would like to provide certain ones jsp functionality. The examples are currently at: /usr/lib/apache-tomcat/webapps/jsp-examples. What is required to run a jsp script from a respective vhost web directory which is located here: /home/ This is where all of the static html pages are stored.

Specifically (I am new to jsp), If I want to move the jsp example files over to the vhost web directory, what all would I need to do?

How would I need to configure the vhost within the server.xml file?

Specifically, if I just want to test the colrs.jsp file by itself, exactly what files would I need to copy over to the vhost web directory?

If my questions do not make much sense, please let me know so I can clarify.

Thanks in advance...
 
FYI, I am not very knowledgable about how JSP's work. Are there any other files/directories such as the class files that will need to be moved or linked to differently when I move location of the JSP/Servlets?
 
Conceptually, this is how it works when you use Apache as a front end to Tomcat:

You have your dynamic website (JSP etc) under Tomcat.
You have your static stuff (images, html etc) under Apache.

You configure Apache to forward all hits for JSP to Tomcat using a JKMount directive in httpd.conf.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
So you are saying that I cannot store the files in a diferent directory? I understand how Apache forwards the JSP requests to Tomcat, but can I not change the location where the JSP's are stored?

It seems to me that when a JSP is referenced, it knows how to interpret it due to the JKMount directive which calls for the respective worker.

I have a webhost control panel that creates sites in the /home/ directory. This is also setup so that the site owner can ftp to this location an upload their files. I have been trying to give them support for JSP/Servlets, so I need to find a way to allow them to store their JSP files there--in their own directory since that is all that they can access on the server anyways.

Does this make sense?
 
I think I have done that, but you may need to confirm my settings. I am trying to access the copied colrs.jsp that I have moved to the /home/ directory. The url is:
Thanks for any additional help you can provide.

###########################################################
workers.properties
###########################################################

workers.tomcat_home=/usr/lib/apache-tomcat

workers.java_home=/usr/lib/jdk

ps=/

worker.list=ajp13

worker.ajp13.port=8009
worker.ajp13.host=localhost
worker.ajp13.type=ajp13

worker.ajp13.lbfactor=1

worker.loadbalancer.type=lb
worker.loadbalancer.balanced_workers=ajp12, ajp13

worker.inprocess.type=jni

worker.inprocess.class_path=$(workers.tomcat_home)$(ps)lib$(ps)tomcat.jar

worker.inprocess.cmd_line=start

worker.inprocess.jvm_lib=$(workers.java_home)$(ps)jre$(ps)lib$(ps)i386$(ps)classic$(ps)libjvm.so

worker.inprocess.stdout=$(workers.tomcat_home)$(ps)logs$(ps)inprocess.stdout
worker.inprocess.stderr=$(workers.tomcat_home)$(ps)logs$(ps)inprocess.stderr

###########################################################
Apache2.conf
###########################################################

...(This is the final section of the file)...

Include /usr/lib/apache-tomcat/conf/auto/mod_jk.conf

# Declare the module for <IfModule directive> (remove this line on Apache 2.0.x)

#AddModule mod_jk.c
# Where to find workers.properties
JkWorkersFile /etc/apache2/workers.properties

# Where to put jk logs
JkLogFile /var/log/apache2/mod_jk.log

# Set the jk log level [debug/error/info]
JkLogLevel info

# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "

# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"

# Deny access to the WEB-INF directory
<LocationMatch '.*WEB-INF.*'>
AllowOverride None
deny from all
</LocationMatch>


###########################################################
VHosts file
###########################################################
<VirtualHost 192.168.2.50:80>
# Send servlet for context /servlets-examples to worker named ajp13
JkMount /*/servlet/* ajp13
# Send JSPs for context /jsp-examples to worker named ajp13
JkMount /*.jsp ajp13
ServerName ServerAdmin webmaster@endorsoft.com
DocumentRoot /home/ServerAlias endorsoft.com
DirectoryIndex index.html index.htm index.php index.php5 index.php4 index.php3 index.shtml index.cgi index.pl index.jsp Default.htm default.htm
ScriptAlias /cgi-bin/ /home/AddHandler cgi-script .cgi
AddHandler cgi-script .pl
ErrorLog /home/AddType application/x-httpd-php .php .php3 .php4 .php5
<Files *.php>
SetOutputFilter PHP
SetInputFilter PHP
</Files>
<Files *.php3>
SetOutputFilter PHP
SetInputFilter PHP
</Files>
<Files *.php4>
SetOutputFilter PHP
SetInputFilter PHP
</Files>
<Files *.php5>
SetOutputFilter PHP
SetInputFilter PHP
</Files>
php_admin_flag safe_mode Off
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
Alias /error/ "/home/ErrorDocument 400 /error/invalidSyntax.html
ErrorDocument 401 /error/authorizationRequired.html
ErrorDocument 403 /error/forbidden.html
ErrorDocument 404 /error/fileNotFound.html
ErrorDocument 405 /error/methodNotAllowed.html
ErrorDocument 500 /error/internalServerError.html
ErrorDocument 503 /error/overloaded.html
AliasMatch ^/~([^/]+)(/(.*))? /home/AliasMatch ^/users/([^/]+)(/(.*))? /home/</VirtualHost>

###########################################################
server.xml
###########################################################
<Server port="8005" shutdown="SHUTDOWN">

<!-- Comment these entries out to disable JMX MBeans support used for the
administration web application -->
<Listener className="org.apache.catalina.core.AprLifecycleListener" />
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/>

<!-- Global JNDI resources -->
<GlobalNamingResources>

<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users -->
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />

</GlobalNamingResources>


<!-- Define the Tomcat Stand-Alone Service -->
<Service name="Catalina">

<!-- A "Connector" represents an endpoint by which requests are received
and responses are returned. Each Connector passes requests on to the
associated "Container" (normally an Engine) for processing.
-->

<!-- Define a non-SSL HTTP/1.1 Connector on port 2117 (default 8080) -->
<Connector port="2117" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="5" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" />


<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" maxThreads="150" minSpareThreads="5" maxSpareThreads="75"
enableLookups="true" redirectPort="8443" protocol="AJP/1.3" />

<!-- An Engine represents the entry point (within Catalina) that processes
every request. The Engine implementation for Tomcat stand alone
analyzes the HTTP headers included with the request, and passes them
on to the appropriate Host (virtual host). -->

<!-- Define the top level container in our container hierarchy -->
<Engine name="Catalina" defaultHost="localhost">

<Realm className="org.apache.catalina.realm.JDBCRealm"
driverName="org.gjt.mm.mysql.Driver"
connectionURL="jdbc:mysql://localhost/authority"
connectionName="test" connectionPassword="test"
userTable="users" userNameCol="user_name" userCredCol="user_pass"
userRoleTable="user_roles" roleNameCol="role_name" />

<Logger className="org.apache.catalina.logger.FileLogger"
prefix="catalina_log." suffix=".txt"
timestamp="true"/>


<!-- Define the default virtual host -->

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

<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="logs" prefix="localhost_access_log." suffix=".txt"
pattern="common" resolveHosts="false"/>
</Host>

<Host name=" appBase="/home/ unpackWARs="true" autoDeploy="true">

<Context path="" docBase="/home/ debug="0" reloadable="true"/>

<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="logs" prefix="web2_access_log." suffix=".txt"
pattern="common" resolveHosts="false"/>
</Host>


<Listener className="org.apache.jk.config.ApacheConfig"
modJk="/usr/lib/apache2/modules/mod_jk.so"
workersConfig="/etc/apache2/conf.d/workers.properties"/>

</Engine>
</Service>
</Server>

###########################################################
mod_jk.conf
###########################################################
########## Auto generated on Tue Feb 07 15:44:33 EST 2006##########

<IfModule !mod_jk.c>
LoadModule jk_module "/usr/lib/apache2/modules/mod_jk.so"
</IfModule>


<VirtualHost localhost>
ServerName localhost

JkMount /webdav ajp13
JkMount /webdav/* ajp13

JkMount /servlets-examples ajp13
JkMount /servlets-examples/* ajp13

JkMount /jsp-examples ajp13
JkMount /jsp-examples/* ajp13

JkMount /balancer ajp13
JkMount /balancer/* ajp13

JkMount /host-manager ajp13
JkMount /host-manager/* ajp13

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

JkMount /manager ajp13
JkMount /manager/* ajp13
</VirtualHost>
 
I don't think you want " in either config files - just "
And you want to change :

<Context path="" docBase="/home/ debug="0" reloadable="true"/>


to :

<Context path="" docBase="jsp-examples" debug="0" reloadable="true"/>


--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Ok, I made the changes and tried it without success. I did restart both servers. One thing I forgot about though is that when I shutdown Tomcat, I get an error. This error started after I removed some of the settings that seemed irrelevant in the server.xml file yesterday. I am going to look back and see what I may have removed, but does this error give you any ideas and do you think it may be the problem as to why I cannot get the jsp to work?

Btw, Tomcat seems to start just fine.

Here is the error:
server1:/usr/lib/apache-tomcat/bin# sh shutdown.sh
Using CATALINA_BASE: /usr/lib/apache-tomcat
Using CATALINA_HOME: /usr/lib/apache-tomcat
Using CATALINA_TMPDIR: /usr/lib/apache-tomcat/temp
Using JRE_HOME: /usr/lib/jdk
Feb 8, 2006 11:12:02 AM org.apache.catalina.startup.Catalina stopServer
SEVERE: Catalina.stop:
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:507)
at java.net.Socket.connect(Socket.java:457)
at java.net.Socket.<init>(Socket.java:365)
at java.net.Socket.<init>(Socket.java:178)
at org.apache.catalina.startup.Catalina.stopServer(Catalina.java:394)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.catalina.startup.Bootstrap.stopServer(Bootstrap.java:324)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:415)
 
That error means that the tomcat shutdown job cannot access the connector port for some reason, such as, tomcat is not running, or not listening on the port it expects.

I would put the config you removed back in !!!

In debugging this problem you need to two things to start :

1) Is Apache actually forwarding the requests to Tomcat ?
2) If Tomcat is recieving the requests, then what is the error you as a user see, and are there any log messages ?

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Well, good news! I figured it out. Turns out that it was just a typo in the server.xml file. I have moved all the example files and they are all working. Even the servlets under the new directory.

Thanks for the help so much!!!
 
sedj,

Two more quick questions if you have time to answer them.

1) When I reboot my server, will Tomcat automatically startup or is there something else I need to do? Also, which starts first, Apache or Tomcat?

2) How does the mod_jk.conf auto config file automatically enter the vhost info? Where does it read this data? More specifically, how did it know to enter the servlets-examples, web_dav, and the other entries. In the server.xml, I only entered data on the jsp-examples...

mod_jk.conf
###########################################################
########## Auto generated on Wed Feb 08 15:07:55 EST 2006##########

<IfModule !mod_jk.c>
LoadModule jk_module "/usr/lib/apache2/modules/mod_jk.so"
</IfModule>

JkWorkersFile "/etc/apache2/workers.properties"
JkLogFile "/usr/lib/apache-tomcat/logs/mod_jk.log"

JkLogLevel emerg



<VirtualHost localhost>
ServerName localhost

JkMount /webdav ajp13
JkMount /webdav/* ajp13

JkMount /servlets-examples ajp13
JkMount /servlets-examples/* ajp13

JkMount /jsp-examples ajp13
JkMount /jsp-examples/* ajp13

JkMount /balancer ajp13
JkMount /balancer/* ajp13

JkMount /host-manager ajp13
JkMount /host-manager/* ajp13

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

JkMount /manager ajp13
JkMount /manager/* ajp13
</VirtualHost>

<VirtualHost ServerName
JkMount /webdav ajp13
JkMount /webdav/* ajp13

JkMount /servlets-examples ajp13
JkMount /servlets-examples/* ajp13

JkMount /jsp-examples ajp13
JkMount /jsp-examples/* ajp13

JkMount /balancer ajp13
JkMount /balancer/* ajp13

JkMount /tomcat-docs ajp13
JkMount /tomcat-docs/* ajp13
</VirtualHost>
 
Okay, disregard the last post.

I have two virtual host sites running the JSP example files without any known problems, but I am getting a couple strange errors/warnings:

#1 When restarting Apache:
###########################################################

server1:# /etc/init.d/apache2 restart
Forcing reload of web server: Apache2[Fri Feb 10 11:28:00 2006][warn]VirtualHost overlaps with VirtualHost the first has precedence, perhaps you need a NameVirtualHost directive
[Fri Feb 10 11:28:02 2006]
[warn] VirtualHost overlaps with VirtualHost the first has precedence, perhaps you need a NameVirtualHost directive



#2 In my catalina.2006.log file I keep getting this error
which repeats every 10 seconds or so and is really
filling up the log fast. Would it have anything to do
with the .xml.xml extension?
###########################################################

Feb 10, 2006 11:33:56 AM org.apache.catalina.startup.HostConfig deployDescriptor
SEVERE: Error deploying configuration descriptor jsp-examples#WEB-INF#web.xml.xml
java.lang.NullPointerException
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:576)
at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:535)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:470)
at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1181)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:292)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1304)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1568)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1577)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1557)
at java.lang.Thread.run(Thread.java:595)
 
Not sure about the Apache error - have you tried the Apache forum ?

Do you actually have a file named web.xml.xml ? If so, I would say that was a problem.

You may want to consider deleting TOMCAT_HOME/work/* to clean out any old config problems.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
This is the actual filename:
jsp-examples#WEB-INF#web.xml.xml

I have no idea where it came from. I will clear out my work directory as you indicated and restart Tomcat/Apache.
 
btw, the jsp-examples#WEB-INF#web.xml.xml file is located in /usr/lib/apache-tomcat/conf/Catalina/localhost/
 
Seems a bit odd ... did you create that file ?
What happens if you delete it ?
Whats actually in the file ?

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
No, I did not purposely create the file.

I did move it out of the directory and see if the errors resume.
Tomcat started up without a problem and the log is error free now. Thanks for the pointer. I believe this file was created by my mistake. I should be more careful in the future... :)

Thanks for the assistance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top