You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Jacob Rhoden <ja...@rhoden.id.au> on 2007/01/04 02:19:47 UTC

Problem setting server.xml field.

Hi Guys,

I am new to all this so it could be a stupid question. In my server.xml 
I have setup a second <host> entry, to enable mapping of a particuar 
application to a virtual host in apache (via mod_jk2). The following 
seems to work ok, except or a possible bug:

      <Host name="fish.org" appBase="webapps" unpackWARs="true">
        <Logger className="org.apache.catalina.logger.FileLogger"
                 directory="logs"  prefix="virtual_log." suffix=".txt" 
timestamp="true"/>
        <Context path="" docBase="/usr/local/tomcat/webapps/FishApp" 
debug="0" reloadable="true"/>
      </Host>

The docbase is set to the path to the application i wish to see in my 
virtual host container. This works when i startup tomcat. However if i 
undeploy/redeploy the application within the tomcat manager, it no 
longer works. Its as if the Host entry stops working or disapears when 
you undeploy, never to return again. Has anyone had this problem? How do 
you fix it?

Best Regards,
Jacob


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Problem setting server.xml field.

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: William Holloway [mailto:wjholloway@gmail.com] 
> Subject: Re: Problem setting server.xml <host> <context> field.
> 
> Is the use the name ROOT required for the WAR or is there 
> another way to specify the default context for the Host?

If the webapp is deployed under the <Host>'s appBase directory, then
yes, the name must be ROOT.  If you don't want to use the name of the
installation directory (or .war file) as the app name, put it somewhere
other than under appBase, and create a ROOT.xml file in
conf/Catalina/[host] that contains a <Context> element with a docBase
attribute that specifies the app location.  Somewhere along the line,
the name ROOT must get associated with the app, unless you put the
<Context> element in server.xml, as you discovered.

> I ask because the our development environment uses only the
> localhost Host and being able to copy WARs from the webapps
> dir of dev server to the appBase of the prod environment
> without refactoring would be really nice.

What refactoring?  Ideally, the app should not be cognizant of where
it's deployed or the name it's deployed as.

> I've tried editing the context after exploding the war
> to the empty path attribute but this doesn't work.  Oddly
> enough, this does work if the context info is copied from
> the context.xml file and pasted into server.xml (followed
> by a restart of tomcat).

That's not odd, that's exactly how the doc says it's supposed to work.
Putting <Context> elements in server.xml is strongly discouraged and is
available primarily for compatibility with older levels.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Problem setting server.xml field.

Posted by William Holloway <wj...@gmail.com>.
I'm attempting a very similar setup and have been successful using the
info described here. Thanks for providing the detailed walk-through.

I have a follow up question, though. Is the use the name ROOT required
for the WAR or is there another way to specify the default context for
the Host? I ask because the our development environment uses only the
localhost Host and being able to copy WARs from the webapps dir of dev
server to the appBase of the prod environment without refactoring
would be really nice. I've tried editing the context after exploding
the war to the empty path attribute but this doesn't work. Oddly
enough, this does work if the context info is copied from the
context.xml file and pasted into server.xml (followed by a restart of
tomcat).

ie this works:

  <Host name="zorp.org" appBase="/vhosts/zorp" autoDeploy="false">
      	
      	<Context path="" docBase=""  reloadable="true">
	</Context>
      </Host>

where as this does not
 <Host name="zorp.org" appBase="/vhosts/zorp" autoDeploy="false">
 </Host>

 and $CATALINA_HOME/conf/Catalina/zorp.org/zorp.xml is

	<Context path="" docBase=""  reloadable="true">
	</Context>

Many thanks,
bill

On 1/3/07, Caldarale, Charles R <Ch...@unisys.com> wrote:
> > From: Jacob Rhoden [mailto:jacob@rhoden.id.au]
> > Subject: Re: Problem setting server.xml <host> <context> field.
>
> > I would like to use virtual hosts so that:
> > mainserver.com:8080/Application1/index.jsp maps to fish.com/index.jsp
> > mainserver.com:8080/Application2/index.jsp maps to
> apples.com/index.jsp
>
> The preliminary question is: do you really need to use httpd or other
> front end to Tomcat at all?  Response will generally be faster without
> something else up front adding path length.  If you do need to front end
> Tomcat, someone else will have to help you with that config, since I
> have very, very limited experience with mod_jk.
>
> Proceeding with a stand-alone config, the first step is to read the
> docs, if you haven't already done so:
> http://tomcat.apache.org/tomcat-5.5-doc/config/host.html
> http://tomcat.apache.org/tomcat-5.5-doc/config/context.html
>
> You should have two <Host> elements with name attributes "fish.com" and
> "apples.com" respectively in server.xml, inside the <Engine> element.
> One of your <Host> names must be declared to be the default one in your
> <Engine> element, since some requests may come in via IP address rather
> than a name.  (You could always define a third one - such as the
> existing localhost - for that purpose.)  You only need one <Connector>
> inside your <Engine>; it will handle requests for all <Host>s.  If you
> get rid of the front end and mod_jk, just use the HTTP version and set
> the port number to 80.
>
> The two (or three) <Host> elements should use unique appBase settings to
> avoid overlapping deployments; for example, you could use
> webapps.fish.com and webapps.apples.com (leaving the plain webapps for
> the third default <Host> if you go that way).  The default app for each
> <Host> should be deployed under its appBase directory in the ROOT
> subdirectory (or as ROOT.war) - note that this name is case sensitive.
> So, your index.jsp files would be located in
> webapps.fish.com/ROOT/index.jsp and webapps.apples.com/ROOT/index.jsp
> for Application1 and Application2, respectively, along with the rest of
> the components of each app.
>
> You likely do not need <Context> elements for your apps, since Tomcat
> uses the name of the deployment directory to derive the URL path for the
> app, with ROOT being the required alias for the default app (what used
> to be specified with an empty string path attribute).  If you really
> have to use <Context> elements, they should be placed in context.xml
> files in each app's META-INF directory (in the ongoing example, that
> would be webapps.fish.com/ROOT/META-INF/context.xml and
> webapps.apples.com/ROOT/META-INF/context.xml).  Such <Context> elements
> must not contain path or docBase attributes.
>
> You can also choose to deploy your apps outside of the <Host> appBase
> directories.  If you wish to do so, you will need ROOT.xml files in
> conf/Catalina/fish.com and conf/Catalina/apples.com.  Each of these
> ROOT.xml files must contain a single <Context> element with a docBase
> attribute pointing to the location of each <Host>'s respective default
> app.  Again, the path attribute must not be used.
>
>  - Chuck
>
>
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
> MATERIAL and is thus for use only by the intended recipient. If you
> received this in error, please contact the sender and delete the e-mail
> and its attachments from all computers.
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Problem setting server.xml field.

Posted by Mark Thomas <ma...@apache.org>.
Jacob Rhoden wrote:
> Thanks for your reply! I was not aware that mod_jk2 was not the best one
> to use (I assumed 2=apache2).  Rather than fixing my mess, how about I
> ask a different question! I am using the latest version of tomcat, I
> would like to have a single version of tomcat running on one port, which
> I can deploy multiple applications.
> 
> I would like to use virtual hosts so that:
> mainserver.com:8080/Application1/index.jsp maps to fish.com/index.jsp
> mainserver.com:8080/Application2/index.jsp maps to apples.com/index.jsp

This, soon to be part of the Tomcat docs, how-to may help

http://webtuitive.com/samples/virtual-hosting-howto.jsp

Mark


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Problem setting server.xml field.

Posted by Jacob Rhoden <ja...@rhoden.id.au>.
Jacob Rhoden wrote:
> My question now however is, the manager to manage deployment of war 
> files seems only to work for the first <Host> container with directory 
> /usr/local/webapps. How do I make it work for both? Do I have to load 
> two copies of the manager somehow? (I dont have much memory on this 
> machine)
>
> ie http://fish.com/manager/html/ works but not 
> http://apple.com/manager/html
>
Nevermind, I have answered my own question, i misread the tutorial. The 
link to the document on setting up a virtual host is good, it should be 
in the documentation. Well its good if you read it properly (: 

Thanks for your all feedback! Very pleasantly surprising!

Best Regards,
Jacob

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Problem setting server.xml field.

Posted by Jacob Rhoden <ja...@rhoden.id.au>.
>> I would like to use virtual hosts so that:
>> mainserver.com:8080/Application1/index.jsp maps to fish.com/index.jsp
>> mainserver.com:8080/Application2/index.jsp maps to apple.com/index.jsp


Thanks for your patience, I have one final question I think, Based on 
previous posts, I have created inside <Engine> two <Host> containers for 
both apple.com and fish.com with paths:
/usr/local/webapps
/usr/local/webapps2

Each domain is now successfully serving its own apps in the equivalent 
directory and each app has its own META-INF/Context.xml

My question now however is, the manager to manage deployment of war 
files seems only to work for the first <Host> container with directory 
/usr/local/webapps. How do I make it work for both? Do I have to load 
two copies of the manager somehow? (I dont have much memory on this machine)

ie http://fish.com/manager/html/ works but not http://apple.com/manager/html

Thanks,
Jacob




---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Problem setting server.xml field.

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Jacob Rhoden [mailto:jacob@rhoden.id.au] 
> Subject: Re: Problem setting server.xml <host> <context> field.

> I would like to use virtual hosts so that:
> mainserver.com:8080/Application1/index.jsp maps to fish.com/index.jsp
> mainserver.com:8080/Application2/index.jsp maps to
apples.com/index.jsp

The preliminary question is: do you really need to use httpd or other
front end to Tomcat at all?  Response will generally be faster without
something else up front adding path length.  If you do need to front end
Tomcat, someone else will have to help you with that config, since I
have very, very limited experience with mod_jk.

Proceeding with a stand-alone config, the first step is to read the
docs, if you haven't already done so:
http://tomcat.apache.org/tomcat-5.5-doc/config/host.html
http://tomcat.apache.org/tomcat-5.5-doc/config/context.html

You should have two <Host> elements with name attributes "fish.com" and
"apples.com" respectively in server.xml, inside the <Engine> element.
One of your <Host> names must be declared to be the default one in your
<Engine> element, since some requests may come in via IP address rather
than a name.  (You could always define a third one - such as the
existing localhost - for that purpose.)  You only need one <Connector>
inside your <Engine>; it will handle requests for all <Host>s.  If you
get rid of the front end and mod_jk, just use the HTTP version and set
the port number to 80.

The two (or three) <Host> elements should use unique appBase settings to
avoid overlapping deployments; for example, you could use
webapps.fish.com and webapps.apples.com (leaving the plain webapps for
the third default <Host> if you go that way).  The default app for each
<Host> should be deployed under its appBase directory in the ROOT
subdirectory (or as ROOT.war) - note that this name is case sensitive.
So, your index.jsp files would be located in
webapps.fish.com/ROOT/index.jsp and webapps.apples.com/ROOT/index.jsp
for Application1 and Application2, respectively, along with the rest of
the components of each app.

You likely do not need <Context> elements for your apps, since Tomcat
uses the name of the deployment directory to derive the URL path for the
app, with ROOT being the required alias for the default app (what used
to be specified with an empty string path attribute).  If you really
have to use <Context> elements, they should be placed in context.xml
files in each app's META-INF directory (in the ongoing example, that
would be webapps.fish.com/ROOT/META-INF/context.xml and
webapps.apples.com/ROOT/META-INF/context.xml).  Such <Context> elements
must not contain path or docBase attributes.

You can also choose to deploy your apps outside of the <Host> appBase
directories.  If you wish to do so, you will need ROOT.xml files in
conf/Catalina/fish.com and conf/Catalina/apples.com.  Each of these
ROOT.xml files must contain a single <Context> element with a docBase
attribute pointing to the location of each <Host>'s respective default
app.  Again, the path attribute must not be used.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Problem setting server.xml field.

Posted by Jacob Rhoden <ja...@rhoden.id.au>.
Thanks for your reply! I was not aware that mod_jk2 was not the best one 
to use (I assumed 2=apache2).  Rather than fixing my mess, how about I 
ask a different question! I am using the latest version of tomcat, I 
would like to have a single version of tomcat running on one port, which 
I can deploy multiple applications.

I would like to use virtual hosts so that:
mainserver.com:8080/Application1/index.jsp maps to fish.com/index.jsp
mainserver.com:8080/Application2/index.jsp maps to apples.com/index.jsp

Ignoring the mess i have made, how would i do this?  Any help or 
pointers to documents that might help would be much appreciated!

Best Regards,
Jacob

Caldarale, Charles R wrote:
>> From: Jacob Rhoden [mailto:jacob@rhoden.id.au] 
>> Subject: Problem setting server.xml <host> <context> field.
>>
>> I have setup a second <host> entry, to enable mapping of a particuar 
>> application to a virtual host in apache (via mod_jk2).
>>     
>
> You do know that mod_jk2 has been deprecated for almost two years?
> Pretty much all the useful stuff has been implemented in mod_jk in the
> interim.
>
>   
>> The following seems to work ok, except or a possible bug:
>>       <Host name="fish.org" appBase="webapps" unpackWARs="true">
>>         <Logger className="org.apache.catalina.logger.FileLogger"
>>                  directory="logs"  prefix="virtual_log." 
>> suffix=".txt" timestamp="true"/>
>>         <Context path="" docBase="/usr/local/tomcat/webapps/FishApp" 
>> debug="0" reloadable="true"/>
>>       </Host>
>>     
>
> You probably don't want the two <Host> entries to use the same appBase,
> unless you really want the apps deployed in both of them at the same
> time.  You don't say what level of Tomcat you're using, but with current
> versions (5.0 and beyond), the above will get the app deployed twice
> under fish.org, once as the default, once as FishApp.  The doc for
> current levels also recommends quite strongly against putting <Context>
> elements inside server.xml.
>
>   
>> However if i undeploy/redeploy the application within the 
>> tomcat manager, it no longer works.
>>     
>
> You need to have a separate manager app for each <Host>.  In current
> levels, this would be accomplished by putting a manager.xml file in
> conf/Catalina/fish.org as well as the usual conf/Catalina/localhost.
> However, unless the overlap of the deployment directories of the two
> <Host>s is straightened out, I suspect it will never work reliably.
>
>  - Chuck
>
>
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
> MATERIAL and is thus for use only by the intended recipient. If you
> received this in error, please contact the sender and delete the e-mail
> and its attachments from all computers.
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>   


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Problem setting server.xml field.

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Jacob Rhoden [mailto:jacob@rhoden.id.au] 
> Subject: Problem setting server.xml <host> <context> field.
> 
> I have setup a second <host> entry, to enable mapping of a particuar 
> application to a virtual host in apache (via mod_jk2).

You do know that mod_jk2 has been deprecated for almost two years?
Pretty much all the useful stuff has been implemented in mod_jk in the
interim.

> The following seems to work ok, except or a possible bug:
>       <Host name="fish.org" appBase="webapps" unpackWARs="true">
>         <Logger className="org.apache.catalina.logger.FileLogger"
>                  directory="logs"  prefix="virtual_log." 
> suffix=".txt" timestamp="true"/>
>         <Context path="" docBase="/usr/local/tomcat/webapps/FishApp" 
> debug="0" reloadable="true"/>
>       </Host>

You probably don't want the two <Host> entries to use the same appBase,
unless you really want the apps deployed in both of them at the same
time.  You don't say what level of Tomcat you're using, but with current
versions (5.0 and beyond), the above will get the app deployed twice
under fish.org, once as the default, once as FishApp.  The doc for
current levels also recommends quite strongly against putting <Context>
elements inside server.xml.

> However if i undeploy/redeploy the application within the 
> tomcat manager, it no longer works.

You need to have a separate manager app for each <Host>.  In current
levels, this would be accomplished by putting a manager.xml file in
conf/Catalina/fish.org as well as the usual conf/Catalina/localhost.
However, unless the overlap of the deployment directories of the two
<Host>s is straightened out, I suspect it will never work reliably.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org