You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Steve Heard <sh...@publicinteractive.com> on 2001/08/20 18:39:09 UTC

VHosts causing app to load twice

I have a servlet based application that needs to be accessed using both the
the server IP address and the server domain name.

The problem is that because I have two <host> entries for the same
application tomcat "loads" them twice. Not only does this leave me with two
instances of the servlets, but the ones I have  marked to load on init have
their code called twice which interferes with itself.

I have tried every combination of VirtualHosts I can think of and always run
into the issue of in order for Tomcat to recognize that it should handle the
request to the servlet I have to add a <Host> entry in server.xml. If I
leave out the entry for the IP address Apache passes the request along to
tomcat fine, but then Tomcat doesn't recognize it. Likewise for the domain
name. 

Any thoughts or help? I have included snippets of what I think are the
relevant config files and how they should look.

-Steve

----------------------------------------------
>From http.conf: 

...

NameVirtualHost 111.22.33.44

<VirtualHost 111.22.33.44 >
  ServerName 111.22.33.44
  ErrorLog /usr/local/apache/logs/error_log
  DocumentRoot /usr/local/apache/htdocs
 
  JkMount /*.servlet ajp13
</VirtualHost>

<VirtualHost 111.22.33.44 >
  ServerName www.foo.com
  ErrorLog /usr/local/apache/logs/error_log
  DocumentRoot /usr/local/apache/htdocs

  JkMount /*.servlet ajp13
</VirtualHost>
----------------------------------------------

----------------------------------------------
>From server.xml:

...

<Host name="111.22.33.44" >
  <Context path="" docBase="/usr/local/apache/servlets" />
</Host>


<Host name="www.foo.com" >
  <Context path="" docBase="/usr/local/apache/servlets" />
 </Host>

...
----------------------------------------------


Re: VHosts causing app to load twice

Posted by Jeff Kilbride <je...@kilbride.com>.
Hi Steve,

I ran into the same problem when trying to configure "mydomain.com" and
"www.mydomain.com" under the same VHost. I was using the "ServerAlias"
directive in Apache. Tomcat (3.2.x) needed two Host directives to deal with
both names, which would give me two instances of my webapp. I finally gave
up and only implemented the "www.mydomain.com"

I'm under the impression that TC 4.0b7 has the ability to add aliases much
like Apache using an "Alias" directive in server.xml. You might want to
check that out. Also, someone posted a patch for 3.2.x to the tomcat-dev
list a month or so ago that allowed you to use a list of domain names in
your "Host" directive, like:

<Host name="mydomain.com www.mydomain.com 111.222.333.444">

You might want to search the dev archives and try this patch. I haven't
tried it yet, so I don't know if it works.

Thanks,
--jeff

----- Original Message -----
From: "Steve Heard" <sh...@publicinteractive.com>
To: <to...@jakarta.apache.org>
Sent: Monday, August 20, 2001 10:43 AM
Subject: Re: VHosts causing app to load twice


> Jeff,
> I am indeed running other hosts on this guy, just didn't include them in
the
> snippet! Sorry about that.
> Thanks,
> steve
>
>
>
> on 8/20/01 1:07 PM, Jeff Kilbride at jeff@kilbride.com wrote:
>
> > Hi Steve,
> >
> > If you must be able to pull this site up by it's IP Address, then you
must
> > not be VHosting any other domains on this IP. Is that correct?
> >
> > If so, you should be using IP-based VHosting instead of Name-based.
IP-based
> > VHosting will associate one IP with one domain name. Tomcat shouldn't
have a
> > problem once it's set up this way.
> >
> > Check out:
> >
> > http://httpd.apache.org/docs/vhosts/ip-based.html
> >
> > Thanks,
> > --jeff
> >
> > ----- Original Message -----
> > From: "Steve Heard" <sh...@publicinteractive.com>
> > To: <to...@jakarta.apache.org>
> > Sent: Monday, August 20, 2001 9:39 AM
> > Subject: VHosts causing app to load twice
> >
> >
> >> I have a servlet based application that needs to be accessed using both
> > the
> >> the server IP address and the server domain name.
> >>
> >> The problem is that because I have two <host> entries for the same
> >> application tomcat "loads" them twice. Not only does this leave me with
> > two
> >> instances of the servlets, but the ones I have  marked to load on init
> > have
> >> their code called twice which interferes with itself.
> >>
> >> I have tried every combination of VirtualHosts I can think of and
always
> > run
> >> into the issue of in order for Tomcat to recognize that it should
handle
> > the
> >> request to the servlet I have to add a <Host> entry in server.xml. If I
> >> leave out the entry for the IP address Apache passes the request along
to
> >> tomcat fine, but then Tomcat doesn't recognize it. Likewise for the
domain
> >> name.
> >>
> >> Any thoughts or help? I have included snippets of what I think are the
> >> relevant config files and how they should look.
> >>
> >> -Steve
> >>
> >> ----------------------------------------------
> >>> From http.conf:
> >>
> >> ...
> >>
> >> NameVirtualHost 111.22.33.44
> >>
> >> <VirtualHost 111.22.33.44 >
> >> ServerName 111.22.33.44
> >> ErrorLog /usr/local/apache/logs/error_log
> >> DocumentRoot /usr/local/apache/htdocs
> >>
> >> JkMount /*.servlet ajp13
> >> </VirtualHost>
> >>
> >> <VirtualHost 111.22.33.44 >
> >> ServerName www.foo.com
> >> ErrorLog /usr/local/apache/logs/error_log
> >> DocumentRoot /usr/local/apache/htdocs
> >>
> >> JkMount /*.servlet ajp13
> >> </VirtualHost>
> >> ----------------------------------------------
> >>
> >> ----------------------------------------------
> >>> From server.xml:
> >>
> >> ...
> >>
> >> <Host name="111.22.33.44" >
> >> <Context path="" docBase="/usr/local/apache/servlets" />
> >> </Host>
> >>
> >>
> >> <Host name="www.foo.com" >
> >> <Context path="" docBase="/usr/local/apache/servlets" />
> >> </Host>
> >>
> >> ...
> >> ----------------------------------------------
> >>
> >
> >
>


Re: VHosts causing app to load twice

Posted by Steve Heard <sh...@publicinteractive.com>.
Jeff,
I am indeed running other hosts on this guy, just didn't include them in the
snippet! Sorry about that.
Thanks,
steve



on 8/20/01 1:07 PM, Jeff Kilbride at jeff@kilbride.com wrote:

> Hi Steve,
> 
> If you must be able to pull this site up by it's IP Address, then you must
> not be VHosting any other domains on this IP. Is that correct?
> 
> If so, you should be using IP-based VHosting instead of Name-based. IP-based
> VHosting will associate one IP with one domain name. Tomcat shouldn't have a
> problem once it's set up this way.
> 
> Check out:
> 
> http://httpd.apache.org/docs/vhosts/ip-based.html
> 
> Thanks,
> --jeff
> 
> ----- Original Message -----
> From: "Steve Heard" <sh...@publicinteractive.com>
> To: <to...@jakarta.apache.org>
> Sent: Monday, August 20, 2001 9:39 AM
> Subject: VHosts causing app to load twice
> 
> 
>> I have a servlet based application that needs to be accessed using both
> the
>> the server IP address and the server domain name.
>> 
>> The problem is that because I have two <host> entries for the same
>> application tomcat "loads" them twice. Not only does this leave me with
> two
>> instances of the servlets, but the ones I have  marked to load on init
> have
>> their code called twice which interferes with itself.
>> 
>> I have tried every combination of VirtualHosts I can think of and always
> run
>> into the issue of in order for Tomcat to recognize that it should handle
> the
>> request to the servlet I have to add a <Host> entry in server.xml. If I
>> leave out the entry for the IP address Apache passes the request along to
>> tomcat fine, but then Tomcat doesn't recognize it. Likewise for the domain
>> name.
>> 
>> Any thoughts or help? I have included snippets of what I think are the
>> relevant config files and how they should look.
>> 
>> -Steve
>> 
>> ----------------------------------------------
>>> From http.conf:
>> 
>> ...
>> 
>> NameVirtualHost 111.22.33.44
>> 
>> <VirtualHost 111.22.33.44 >
>> ServerName 111.22.33.44
>> ErrorLog /usr/local/apache/logs/error_log
>> DocumentRoot /usr/local/apache/htdocs
>> 
>> JkMount /*.servlet ajp13
>> </VirtualHost>
>> 
>> <VirtualHost 111.22.33.44 >
>> ServerName www.foo.com
>> ErrorLog /usr/local/apache/logs/error_log
>> DocumentRoot /usr/local/apache/htdocs
>> 
>> JkMount /*.servlet ajp13
>> </VirtualHost>
>> ----------------------------------------------
>> 
>> ----------------------------------------------
>>> From server.xml:
>> 
>> ...
>> 
>> <Host name="111.22.33.44" >
>> <Context path="" docBase="/usr/local/apache/servlets" />
>> </Host>
>> 
>> 
>> <Host name="www.foo.com" >
>> <Context path="" docBase="/usr/local/apache/servlets" />
>> </Host>
>> 
>> ...
>> ----------------------------------------------
>> 
> 
> 


Re: VHosts causing app to load twice

Posted by Jeff Kilbride <je...@kilbride.com>.
Hi Steve,

If you must be able to pull this site up by it's IP Address, then you must
not be VHosting any other domains on this IP. Is that correct?

If so, you should be using IP-based VHosting instead of Name-based. IP-based
VHosting will associate one IP with one domain name. Tomcat shouldn't have a
problem once it's set up this way.

Check out:

http://httpd.apache.org/docs/vhosts/ip-based.html

Thanks,
--jeff

----- Original Message -----
From: "Steve Heard" <sh...@publicinteractive.com>
To: <to...@jakarta.apache.org>
Sent: Monday, August 20, 2001 9:39 AM
Subject: VHosts causing app to load twice


> I have a servlet based application that needs to be accessed using both
the
> the server IP address and the server domain name.
>
> The problem is that because I have two <host> entries for the same
> application tomcat "loads" them twice. Not only does this leave me with
two
> instances of the servlets, but the ones I have  marked to load on init
have
> their code called twice which interferes with itself.
>
> I have tried every combination of VirtualHosts I can think of and always
run
> into the issue of in order for Tomcat to recognize that it should handle
the
> request to the servlet I have to add a <Host> entry in server.xml. If I
> leave out the entry for the IP address Apache passes the request along to
> tomcat fine, but then Tomcat doesn't recognize it. Likewise for the domain
> name.
>
> Any thoughts or help? I have included snippets of what I think are the
> relevant config files and how they should look.
>
> -Steve
>
> ----------------------------------------------
> >From http.conf:
>
> ...
>
> NameVirtualHost 111.22.33.44
>
> <VirtualHost 111.22.33.44 >
>   ServerName 111.22.33.44
>   ErrorLog /usr/local/apache/logs/error_log
>   DocumentRoot /usr/local/apache/htdocs
>
>   JkMount /*.servlet ajp13
> </VirtualHost>
>
> <VirtualHost 111.22.33.44 >
>   ServerName www.foo.com
>   ErrorLog /usr/local/apache/logs/error_log
>   DocumentRoot /usr/local/apache/htdocs
>
>   JkMount /*.servlet ajp13
> </VirtualHost>
> ----------------------------------------------
>
> ----------------------------------------------
> >From server.xml:
>
> ...
>
> <Host name="111.22.33.44" >
>   <Context path="" docBase="/usr/local/apache/servlets" />
> </Host>
>
>
> <Host name="www.foo.com" >
>   <Context path="" docBase="/usr/local/apache/servlets" />
>  </Host>
>
> ...
> ----------------------------------------------
>