tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Turner <tomcat-u...@johnturner.com>
Subject Re: 2 VirtualHosts same IP address and port on Tomcat not working
Date Fri, 22 Aug 2003 14:51:29 GMT

For grins, I decided to setup an example.  Here it is.

The server has multiple virtual hosts.  There are currently 6 working, 
this configuration describes how I added a seventh by copying a config 
from one of the other 6 and changing values as needed.

The scenario:

One Tomcat instance (4.1.12, yes I know its old but its an internal 
"play" server so not that important)

Multi-virtual hosts, each one has its own appBase ($CATALINA_HOME/hostname).

Each virtual host has a root context ($CATALINA_HOME/hostname/hostname).

Apache 2, mod_jk.so.

The goal:

http://hostname/test.jsp works
http://hostname/test.html works

To setup the new virtual host, I did the following:

- in server.xml, added:

<Host name="www.DOMAIN.com" debug="1" appBase="DOMAIN"
       unpackWARs="true" autoDeploy="true">

     <Logger className="org.apache.catalina.logger.FileLogger"
             directory="logs"  prefix="DOMAIN_com." suffix=".log"
             timestamp="true"/>

     <Context path="" docBase="DOMAIN" debug="0" reloadable="true">

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

     <Resource name="mail/Session" auth="Container"
               type="javax.mail.Session"/>
         <ResourceParams name="mail/Session">
             <parameter>
                 <name>mail.smtp.host</name>
                 <value>localhost</value>
             </parameter>
         </ResourceParams>

     </Context>
</Host>

- created $CATALINA_HOME/DOMAIN, $CATALINA_HOME/DOMAIN/DOMAIN, 
$CATALINA_HOME/DOMAIN/DOMAIN/WEB-INF, 
$CATALINA_HOME/DOMAIN/DOMAIN/WEB-INF/classes, 
$CATALINA_HOME/DOMAIN/DOMAIN/WEB-INF/lib, 
$CATALINA_HOME/DOMAIN/DOMAIN/WEB-INF/web.xml where $CATALINA_HOME = 
"/usr/local/jakarta-tomcat-4.1.12"

- chown -R tomcat:tomcat $CATALINA_HOME/DOMAIN

- created $CATALINA_HOME/DOMAIN/DOMAIN/test.html and 
$CATALINA_HOME/DOMAIN/DOMAIN/test.jsp

in Apache httpd.conf, added:

<VirtualHost *>
     ServerName www.DOMAIN.com
     DocumentRoot /usr/local/jakarta-tomcat-4.1.12/DOMAIN/DOMAIN

     # Static files
     Alias / "/usr/local/jakarta-tomcat-4.1.12/DOMAIN/DOMAIN"

     <Directory "/usr/local/jakarta-tomcat-4.1.12/DOMAIN/DOMAIN">
         Options Indexes FollowSymLinks
         DirectoryIndex index.jsp
     </Directory>

     # Deny direct access to WEB-INF and META-INF
     #
     <Location "/WEB-INF/*">
         AllowOverride None
         deny from all
     </Location>

     <Location "/META-INF/*">
         AllowOverride None
         deny from all
     </Location>

     JkMount /* ajp13

</VirtualHost>

- stopped Tomcat.  stopped Apache.  Removed contents of 
$CATALINA_HOME/work/Standalone.  Started Tomcat.  Started Apache.

- verified that http://www.DOMAIN.com/test.jsp and 
http://www.DOMAIN.com/test.html work, and that 
http://www.DOMAIN.com/WEB-INF/web.xml returns a 403.

Wherever you see "DOMAIN" in the above, substitute the domain name that 
you want to use, or anything else, as long as you stay consistent.

I decided to use a JkMount of "/*" only because that's what you said you 
wanted to do by having a servlet generate all content...I could have 
just as easily made the JkMount be "/*.jsp" or whatever.  Your servlets 
now go in $CATALINA_HOME/DOMAIN/DOMAIN/WEB-INF, and you can adjust your 
web.xml appropriately to map them to a URL starting with "/" as in 
http://www.DOMAIN.com/SERVLET-URL.

Thus, things like "/WEB-INF" in the Location directive are RELATIVE to 
things like Alias, as is JkMount..if you get Alias wrong (and/or 
DocumentRoot) you're going to have lots of problems, and messing with 
your Contexts in server.xml or putting strange onLoad Javascript 
redirects in your pages isn't going to make it any better.

I'm not sure how much clearer I can be than the above, but I am always 
open to suggestions/corrections.

HTH

John

David Wynter wrote:

> Hi,
> 
> It seems that the second VirtualHost I have set up for my second domain name
> is not paasing the requests through mod_jk to Tomcat. It is not even clear
> that you can support 2 virtualhosts for different domains with the same IP
> address and port 80.
> This is a separate problem to the www.stpenable.com not redirecting to
> www.stpenable.com/se/servlet/se/templates/index.vm but it still affects me.
> 
> Is the only way I can support a second virtual host is by setting up a
> second <Service> with its own Engine and Ajp13 connector listening on a
> separate port (say 8007 instead of 8009?). I assume I then setup a second
> worker on the port I have introduced. And in this case do both sevices also
> have a listener for port 8080, or do I need one on that port at all since
> all my trafic will be on port 80?
> 
> I just tried it without a listener on port 8080, and a service with a
> connector on 8007 for one virtual host and a separate service with connector
> on 8009 for the other, nothing worked, so I suppose that answers my
> question.
> 
> I am kinda surprised that on the whole internet there is not a configuration
> example of running different webapps on 2 domains on the same Tomcat
> instance, there must be hundreds of people doing it?
> 
> Thanks
> 
> David
> 
>>-----Original Message-----
>>From: David Wynter [mailto:david@roamware.co.uk]
>>Sent: 21 August 2003 15:39
>>To: Tomcat Users List
>>Subject: RE: 2 VirtualHosts same IP address and port on Tomcat not
>>working
>>
>>
>>Actually I should qualify what I said. I have stpenable as the
>>default Host
>>so you can see www.stpenable.com/se/servlet/se/templates/index.vm  but for
>>some reason you cannot see
>>www.roamware.co.uk/rwsite/servlet/rwsite/templates/index.vm which is the
>>second of the VirtualHosts in my conf file. They are configured
>>as matching
>>patterns (if you know what I mean - only the names have changed
>>between the
>>2 configs).
>>
>>The DefualHost in the Engine is www.stpenable.com
>>
>>Here is the Host section from my server.xml, I've strpped out the
>>comments----------------->
>>
>>      <!-- Define the default virtual host -->
>>      <Host name="localhost" debug="0" appBase="webapps"
>>       unpackWARs="true" autoDeploy="true">
>>
>>        <Logger className="org.apache.catalina.logger.FileLogger"
>>                 directory="logs"  prefix="localhost_log." suffix=".txt"
>>	        timestamp="true"/>
>>
>>      </Host>
>>
>>     <!-- Define the default virtual host -->
>>      <Host name="www.stpenable.com" debug="0" appBase="webapp2"
>>       unpackWARs="true" autoDeploy="true">
>>
>>        <Valve className="org.apache.catalina.valves.AccessLogValve"
>>                 directory="logs"  prefix="stpenable_access_log."
>>suffix=".txt"
>>                 pattern="common"/>
>>
>>        <Logger className="org.apache.catalina.logger.FileLogger"
>>                 directory="logs"  prefix="stpenable_log." suffix=".txt"
>>	        timestamp="true"/>
>>
>>      </Host>
>>
>>      <!-- Define the default virtual host -->
>>      <Host name="www.roamware.co.uk" debug="0" appBase="webapp1"
>>       unpackWARs="true" autoDeploy="true">
>>
>>        <Valve className="org.apache.catalina.valves.AccessLogValve"
>>                 directory="logs"  prefix="stpenable_access_log."
>>suffix=".txt"
>>                 pattern="common"/>
>>
>>
>>        <Logger className="org.apache.catalina.logger.FileLogger"
>>                 directory="logs"  prefix="roamware_log." suffix=".txt"
>>	        timestamp="true"/>
>>
>>      </Host>
>>
>>
>>regards,
>>
>>David
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>>
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 



Mime
View raw message