You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Stephen Carville <st...@totalflood.com> on 2003/06/21 03:21:20 UTC

Virtual domains with Tomcat

How can I get Tomcat to recognize virtual domains?  This is trivial with 
Apache and I can get Apache to fetch the correct jsp but I cannot get timcat 
to process it.  If I turn off tomcat, apache sends the jsp source.  If I turn 
tomcat on, I get the error 404 page

workers.properties:

workers.tomcat_home-/var/jakarta/tomcat
workers.java_home=/usr/java/jdk
ps=/

# worker list
worker.list=ajp13

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

jk.conf: (Included by the httpd.conf file)

LoadModule jk_module modules/mod_jk.so
JkWorkersFile   /etc/httpd/conf/workers.properties
JkLogFile       /var/log/httpd/mod_jk.log

example <Virtual Host>

<VirtualHost *>
        ServerName      dookoo.totalflood.com
        DocumentRoot    /var/jakarta/totalflood/ROOT
  <Directory /var/jakarta/totalflood/ROOT>
        order allow,deny
        allow from all
  </Directory>
        DirectoryIndex  HomePage.jsp
        ErrorLog        /var/log/httpd/totalflood-error.log
        JkMount         /*.jsp  ajp13
</VirtualHost>

-- 
Stephen Carville
UNIX and Network Administrator
DPSI (formerly Ace USA Flood Services)
310-342-3602
stephen@totalflood.com

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Virtual domains with Tomcat

Posted by John Turner <to...@johnturner.com>.
Yes, AFAIK.

As I understand it, the JK/JK2 connectors are pipelines, not pre-or post- 
processors.  They send the request from Apache to Tomcat.  When Tomcat 
receives the request, it is as if Apache doesn't even exist.  Tomcat acts 
the same way it would act if using Tomcat stand-alone.  I could be wrong, 
but I've never been able to successfully setup a virtual hosting 
configuration without defining my virtual hosts in both Apache's httpd.conf 
and Tomcat's server.xml.  If there's a shortcut, I'd love to see it.

John

On Mon, 23 Jun 2003 10:59:33 -0400, Rick Anderson 
<ri...@rci.rutgers.edu> wrote:

> When you use virtual hosts on apache2 with mod_jk2 does Tomcat have to 
> have the same virtual hosts defined in it's server.xml file?
>
> --Rick Anderson
>
>
> John Turner wrote:
>
>>
>> Yes.  In general, for every Apache ServerName, you need a corresponding 
>> Host entry in Tomcat's server.xml.
>>
>> The Apache connectors are just pipelines, they do not do any work on 
>> behalf of Tomcat.  Thus, when Tomcat receives the request, it has to do 
>> the same sort of host header processing that Apache has to do.  If 
>> Tomcat cannot find a Host entry that corresponds to the HTTP Host Header 
>> it is receiving on the request, it will default to the host name listed 
>> in the defaultHost parameter in server.xml.  Apache does the same 
>> thing...if it can't find a VirtualHost to match the host header, it 
>> defaults to the global VirtualHost, or rather the global ServerName.
>>
>> The syntax for defining a virtual host in Tomcat's server.xml is 
>> different than Apache's httpd.conf, but the principles and concepts are 
>> the same.
>>
>> John
>>
>> On Mon, 23 Jun 2003 11:00:58 +0200, Nikola Milutinovic 
>> <Ni...@ev.co.yu> wrote:
>>
>>>> How can I get Tomcat to recognize virtual domains?  This is trivial 
>>>> with Apache and I can get Apache to fetch the correct jsp but I cannot 
>>>> get timcat to process it.  If I turn off tomcat, apache sends the jsp 
>>>> source.  If I turn tomcat on, I get the error 404 page
>>>
>>>
>>> Anything in the logs?
>>>
>>> I'm not totally sure, but I think you need to match VHosts in your 
>>> Apache and your Tomcat. I'll be testing exactly that today with 
>>> mod_jk2, Apache 2.0.46 and Tomcat 4.1.24. For mod_webapp it is definite 
>>> - you need:
>>>
>>> <Service ...>
>>> <Connector ...>
>>> <Engine ...>
>>> <Host name="my-vhost.domain.com" ...>
>>> <Context docBase="..." path=".."/>
>>> ....
>>> </Host>
>>> </Service>
>>>
>>> I think the same applies to all other connectors: mod_jk, mod_jk2 and 
>>> HTTP.
>>>
>>> Nix.
>>>
>>
>>
>>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>



-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Virtual domains with Tomcat

Posted by Rick Anderson <ri...@rci.rutgers.edu>.
When you use virtual hosts on apache2 with mod_jk2 does Tomcat have to 
have the same virtual hosts defined in it's server.xml file?

--Rick Anderson


John Turner wrote:

>
> Yes.  In general, for every Apache ServerName, you need a 
> corresponding Host entry in Tomcat's server.xml.
>
> The Apache connectors are just pipelines, they do not do any work on 
> behalf of Tomcat.  Thus, when Tomcat receives the request, it has to 
> do the same sort of host header processing that Apache has to do.  If 
> Tomcat cannot find a Host entry that corresponds to the HTTP Host 
> Header it is receiving on the request, it will default to the host 
> name listed in the defaultHost parameter in server.xml.  Apache does 
> the same thing...if it can't find a VirtualHost to match the host 
> header, it defaults to the global VirtualHost, or rather the global 
> ServerName.
>
> The syntax for defining a virtual host in Tomcat's server.xml is 
> different than Apache's httpd.conf, but the principles and concepts 
> are the same.
>
> John
>
> On Mon, 23 Jun 2003 11:00:58 +0200, Nikola Milutinovic 
> <Ni...@ev.co.yu> wrote:
>
>>> How can I get Tomcat to recognize virtual domains?  This is trivial 
>>> with Apache and I can get Apache to fetch the correct jsp but I 
>>> cannot get timcat to process it.  If I turn off tomcat, apache sends 
>>> the jsp source.  If I turn tomcat on, I get the error 404 page
>>
>>
>> Anything in the logs?
>>
>> I'm not totally sure, but I think you need to match VHosts in your 
>> Apache and your Tomcat. I'll be testing exactly that today with 
>> mod_jk2, Apache 2.0.46 and Tomcat 4.1.24. For mod_webapp it is 
>> definite - you need:
>>
>> <Service ...>
>> <Connector ...>
>> <Engine ...>
>> <Host name="my-vhost.domain.com" ...>
>> <Context docBase="..." path=".."/>
>> ....
>> </Host>
>> </Service>
>>
>> I think the same applies to all other connectors: mod_jk, mod_jk2 and 
>> HTTP.
>>
>> Nix.
>>
>
>
>




---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Virtual domains with Tomcat

Posted by John Turner <to...@johnturner.com>.
Yes.  In general, for every Apache ServerName, you need a corresponding 
Host entry in Tomcat's server.xml.

The Apache connectors are just pipelines, they do not do any work on behalf 
of Tomcat.  Thus, when Tomcat receives the request, it has to do the same 
sort of host header processing that Apache has to do.  If Tomcat cannot 
find a Host entry that corresponds to the HTTP Host Header it is receiving 
on the request, it will default to the host name listed in the defaultHost 
parameter in server.xml.  Apache does the same thing...if it can't find a 
VirtualHost to match the host header, it defaults to the global 
VirtualHost, or rather the global ServerName.

The syntax for defining a virtual host in Tomcat's server.xml is different 
than Apache's httpd.conf, but the principles and concepts are the same.

John

On Mon, 23 Jun 2003 11:00:58 +0200, Nikola Milutinovic 
<Ni...@ev.co.yu> wrote:

>> How can I get Tomcat to recognize virtual domains?  This is trivial with 
>> Apache and I can get Apache to fetch the correct jsp but I cannot get 
>> timcat to process it.  If I turn off tomcat, apache sends the jsp 
>> source.  If I turn tomcat on, I get the error 404 page
>
> Anything in the logs?
>
> I'm not totally sure, but I think you need to match VHosts in your Apache 
> and your Tomcat. I'll be testing exactly that today with mod_jk2, Apache 
> 2.0.46 and Tomcat 4.1.24. For mod_webapp it is definite - you need:
>
> <Service ...>
> <Connector ...>
> <Engine ...>
> <Host name="my-vhost.domain.com" ...>
> <Context docBase="..." path=".."/>
> ....
> </Host>
> </Service>
>
> I think the same applies to all other connectors: mod_jk, mod_jk2 and 
> HTTP.
>
> Nix.
>



-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Virtual domains with Tomcat

Posted by Nikola Milutinovic <Ni...@ev.co.yu>.
> How can I get Tomcat to recognize virtual domains?  This is trivial with 
> Apache and I can get Apache to fetch the correct jsp but I cannot get timcat 
> to process it.  If I turn off tomcat, apache sends the jsp source.  If I turn 
> tomcat on, I get the error 404 page

Anything in the logs?

I'm not totally sure, but I think you need to match VHosts in your Apache and your Tomcat. I'll be testing exactly that today with mod_jk2, Apache 2.0.46 and Tomcat 4.1.24. For mod_webapp it is definite - you need:

<Service ...>
  <Connector ...>
  <Engine ...>
  <Host name="my-vhost.domain.com" ...>
    <Context docBase="..." path=".."/>
    ....
  </Host>
</Service>

I think the same applies to all other connectors: mod_jk, mod_jk2 and HTTP.

Nix.

Re: Virtual domains with Tomcat

Posted by Stephen Carville <ca...@cpl.net>.
On Monday June 23 2003 05:45 am, John Turner wrote:
> It is trivial in Tomcat as well.
>
> For each Apache ServerName, you will need a corresponding Host entry in
> Tomcat's server.xml.  Make sure each virtual host in Tomcat's server.xml
> has its own appBase.
>
> For the VirtualHost you posted:
>
> <Host name="dookoo.totalflood.com" appBase="/var/jakarta/totalflood">
>    <Context path="" docBase="ROOT" />
> </Host>

That works.  Thanks. 

I had to remove the <Context ... /> -- It caused tomcat fail.  Howewer, it 
seems it is not necessary.

> ...or something very similar.  Put your JSPs in
> /var/jakarta/totalflood/ROOT.  Make sure there is a directory called
> /var/jakarta/totalflood/ROOT/WEB-INF.  Delete your Directory entry that
> allows all, and instead add a Directory entry that restricts WEB-INF and
> META-INF.  This is all covered in the docs for Host and for Context.  An
> example of what configuration for Apache looks like, for a virtual host
> named "localhost", is here:
>
> http://www.johnturner.com/howto/mod_jk_conf.html
>
> John
>
> On Fri, 20 Jun 2003 18:21:20 -0700, Stephen Carville
>
> <st...@totalflood.com> wrote:
> > How can I get Tomcat to recognize virtual domains?  This is trivial with
> > Apache and I can get Apache to fetch the correct jsp but I cannot get
> > timcat to process it.  If I turn off tomcat, apache sends the jsp source.
> > If I turn tomcat on, I get the error 404 page
> >
> > workers.properties:
> >
> > workers.tomcat_home-/var/jakarta/tomcat
> > workers.java_home=/usr/java/jdk
> > ps=/
> >
> > # worker list
> > worker.list=ajp13
> >
> > worker.ajp13.port=8009
> > worker.ajp13.host=localhost
> > worker.ajp13.type=ajp13
> >
> > jk.conf: (Included by the httpd.conf file)
> >
> > LoadModule jk_module modules/mod_jk.so
> > JkWorkersFile   /etc/httpd/conf/workers.properties
> > JkLogFile       /var/log/httpd/mod_jk.log
> >
> > example <Virtual Host>
> >
> > <VirtualHost *>
> > ServerName      dookoo.totalflood.com
> > DocumentRoot    /var/jakarta/totalflood/ROOT
> > <Directory /var/jakarta/totalflood/ROOT>
> > order allow,deny
> > allow from all
> > </Directory>
> > DirectoryIndex  HomePage.jsp
> > ErrorLog        /var/log/httpd/totalflood-error.log
> > JkMount         /*.jsp  ajp13
> > </VirtualHost>

-- 
Stephen Carville http://www.heronforge.net/~stephen/gnupgkey.txt
------------------------------------------------------------------
Mom & Pop were just a couple of kids when they got married. He was
eighteen, she was sixteen and I was three."
 -- Billie Holiday

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Virtual domains with Tomcat

Posted by John Turner <to...@johnturner.com>.
It is trivial in Tomcat as well.

For each Apache ServerName, you will need a corresponding Host entry in 
Tomcat's server.xml.  Make sure each virtual host in Tomcat's server.xml 
has its own appBase.

For the VirtualHost you posted:

<Host name="dookoo.totalflood.com" appBase="/var/jakarta/totalflood">
   <Context path="" docBase="ROOT" />
</Host>

...or something very similar.  Put your JSPs in 
/var/jakarta/totalflood/ROOT.  Make sure there is a directory called 
/var/jakarta/totalflood/ROOT/WEB-INF.  Delete your Directory entry that 
allows all, and instead add a Directory entry that restricts WEB-INF and 
META-INF.  This is all covered in the docs for Host and for Context.  An 
example of what configuration for Apache looks like, for a virtual host 
named "localhost", is here:

http://www.johnturner.com/howto/mod_jk_conf.html

John

On Fri, 20 Jun 2003 18:21:20 -0700, Stephen Carville 
<st...@totalflood.com> wrote:

> How can I get Tomcat to recognize virtual domains?  This is trivial with 
> Apache and I can get Apache to fetch the correct jsp but I cannot get 
> timcat to process it.  If I turn off tomcat, apache sends the jsp source. 
> If I turn tomcat on, I get the error 404 page
>
> workers.properties:
>
> workers.tomcat_home-/var/jakarta/tomcat
> workers.java_home=/usr/java/jdk
> ps=/
>
> # worker list
> worker.list=ajp13
>
> worker.ajp13.port=8009
> worker.ajp13.host=localhost
> worker.ajp13.type=ajp13
>
> jk.conf: (Included by the httpd.conf file)
>
> LoadModule jk_module modules/mod_jk.so
> JkWorkersFile   /etc/httpd/conf/workers.properties
> JkLogFile       /var/log/httpd/mod_jk.log
>
> example <Virtual Host>
>
> <VirtualHost *>
> ServerName      dookoo.totalflood.com
> DocumentRoot    /var/jakarta/totalflood/ROOT
> <Directory /var/jakarta/totalflood/ROOT>
> order allow,deny
> allow from all
> </Directory>
> DirectoryIndex  HomePage.jsp
> ErrorLog        /var/log/httpd/totalflood-error.log
> JkMount         /*.jsp  ajp13
> </VirtualHost>
>



-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org