You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Marcin Gryszkalis <mg...@fork.pl> on 2003/01/26 20:32:04 UTC
web.xml and ip-based virtual hosts
Hi
I have Tomcat 4.1.x
in configuration there's <server> block that contains two
<service> blocks (I have 2 ip/port-based virtual hosts).
1. How can I specify in application's web.xml which <service>
should it be deployed to?
2. Can I have ip-based virtual hosts with one serice
and multiple <connector>? I guess it's not possible
because there can be only one DefaultContext per Host
(and only one Host/Engine per service).
regards
--
Marcin Gryszkalis
http://fork.pl
<><
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: web.xml and ip-based virtual hosts
Posted by "Craig R. McClanahan" <cr...@apache.org>.
On Sun, 26 Jan 2003, Marcin Gryszkalis wrote:
> Date: Sun, 26 Jan 2003 20:32:04 +0100
> From: Marcin Gryszkalis <mg...@fork.pl>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>
> To: tomcat-user@jakarta.apache.org
> Subject: web.xml and ip-based virtual hosts
>
> Hi
> I have Tomcat 4.1.x
> in configuration there's <server> block that contains two
> <service> blocks (I have 2 ip/port-based virtual hosts).
>
> 1. How can I specify in application's web.xml which <service>
> should it be deployed to?
>
You can't make this determination inside the web.xml file -- instead, the
determination is made in one of two ways, depending on how you've
configured the app in server.xml:
* If you created a <Context> element for your webapp,
it belongs to the <Service> that encloses the <Host>
element you put it inside.
* If you didn't create <Context> element (because you're
relying on the automatic deployment feature), you will
note that each <Host> element has an "appBase" parameter.
The webapp will belong to the <Service> that surrounds
the <Host> element whose "appBase" directory you put the
webapp inside.
> 2. Can I have ip-based virtual hosts with one serice
> and multiple <connector>? I guess it's not possible
> because there can be only one DefaultContext per Host
> (and only one Host/Engine per service).
>
The <DefaultContext> element does not define an actual webapp - it defines
a bunch of default settings for automatically deployed webapps. The
default settings are per-host.
However, it is perfectly legal to have more than one <Connector> per
<Service>.
The overall structure of the server.xml file lets you do pretty much
any combination of things you want to do. Consider the following, for
example (only the important parts called out):
<Server ...>
<Service name="Tomcat-Standalone">
<Connector port="8080" .../>
<Connector port="8081" .../>
<Engine name="Standalone" defaultHost="localhost">
<Host name="localhost" appBase="webapps">
... Optional <DefaultContext> element ...
... Optional <Context> elements ...
</Host>
</Engine>
</Service>
<Service name="My Own Service" ...>
<Connector port="8082" .../>
<Connector port="8083" .../>
<Engine name="First Service Engine">
<Host name="www.mycompany.com" appBase="mycompany">
... Optional <DefaultContext> element ...
... Optional <Context> elements ...
</Host>
<Host name="www.yourcompany.com" appBase="/foo/yourcompany">
... Optional <DefaultContext> element ...
... Optional <Context> elements ...
</Host>
</Engine>
</Service>
</Server>
You might recognize the first <Service> entry as pretty much what the
default Tomcat configuration looks like. It has the following
characteristics:
* All incoming requests on port 8080 and 8081 are processed here.
* No matter what server name or IP address is used on the request,
they are all processed by the "localhost" <Host> element, as long
as the DNS addresses resolve to this server.
* You can optionally nest a <DefaultContext> element to define the
characteristics of all automatically deployed webapps for this host.
* All web applications in the "$CATALINA_HOME/webapps" directory
are automatically deployed at startup time.
* In addition, you can nest <Context> elements with a "docBase" that
points at your application's directory or WAR file. Relative
pathnames are resolved against the "appBase" (in this case, against
"$CATALINA_HOME/webapps"), while absolute pathnames tell Tomcat
exactly where to find your app.
The second <Service> entry is quite a bit different. It has the following
characteristics:
* All incoming requests on port 8082 and 8083 are processed here.
* Only host names "www.mycompany.com" and "www.yourcompany.com" are
recognized (because there is no "defaultHost" element on this <Engine>).
Any request for a different hostname that is received on these
ports will be rejected.
* For each host, you can optionally nest a <DefaultContext> element to
define the characteristics of all automatically deployed webapps
for this host.
* All web applications in the "$CATALINA_HOME/mycompany" directory
will be automatically deployed for the www.mycompany.com host
(relative paths are resolved against $CATALINA_HOME).
* All web applications in the "/foo/yourcompany" directory
will be automatically deployed for the www.yourcompany.com host
(absolute pathnames are legal as well).
* In addition, you can nest <Context> elements under either <Host>
for additional webapps for that host, with a "docBase" attribute
defining where the webapp is on your filesystem. Absolute paths
are resolved relative to the "appBase" directory for your host,
while absolute paths (by definition) tell Tomcat where the webapp
files are.
For further information about all of the elements you can create in
server.xml, see the Configuration Reference information, included in your
Tomcat install or available online:
http://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/
> regards
> --
> Marcin Gryszkalis
> http://fork.pl
> <><
Craig McClanahan
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>