Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Virtual hosts in Tomcat

Status
Not open for further replies.

dparrott

MIS
Jul 26, 2004
201
US
Hey all,

I work for a medium sized company, but we have a fairly small IT staff, none of whom are web guru's. One of the programs we are using for quality stuff runs on Tomcat to give vendors and customers access to the program. We also have two static webpages that we need to host, all from one computer. Currently, we have two IP addresses because they are on different computers (one for one static page, one for the second and the jsp stuff), and ideally we would like to keep them that way.
I have determined that we need virtual hosts. I have found plenty on how to do it with Apache, but nothing on how to do it with Tomcat, other than it can be done. Since there are only 3 of us, and none of us really knows webserver software at all, keeping one program seems easier than using both apache and tomcat and configuring them to work together.
Anyone with any insight into this or who knows a good how/to or FAQ about it, please post the information, it will really help out.

Thanks,

Danny
 
I meant to post this. This is a the current server.xml file i am trying. Tomcat starts fine with this.
Code:
<?xml version='1.0' encoding='utf-8'?>
<Server>
  <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"/>
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
  <GlobalNamingResources>
    <Environment name="simpleValue" type="java.lang.Integer" value="30"/>
    <Resource auth="Container" description="User database that can be updated and saved" name="UserDatabase" type="org.apache.catalina.UserDatabase"/>
    <ResourceParams name="UserDatabase">
      <parameter>
        <name>factory</name>
        <value>org.apache.catalina.users.MemoryUserDatabaseFactory</value>
      </parameter>
      <parameter>
        <name>pathname</name>
        <value>conf/tomcat-users.xml</value>
      </parameter>
    </ResourceParams>
  </GlobalNamingResources>
  <Service name="Catalina">
    <Connector acceptCount="100" connectionTimeout="20000" disableUploadTimeout="true" port="8080" redirectPort="8443">
    </Connector>
    <Connector port="8009" protocol="AJP/1.3" protocolHandlerClassName="org.apache.jk.server.JkCoyoteHandler" redirectPort="8443">
    </Connector>
    <Engine defaultHost="localhost" name="Catalina">
      <Host appBase="webapps/aircommfg" name="aircommfg.com">
	<alias>[URL unfurl="true"]www.aircommfg.com</alias>[/URL]
	<alias>aircommfg</alias>
	<Context path="" docBase="aircommfg">
      </Host>
      <Host appBase="webapps" name="localhost">
        <Logger className="org.apache.catalina.logger.FileLogger" prefix="localhost_log." suffix=".txt" timestamp="true"/>
      </Host>
      <Logger className="org.apache.catalina.logger.FileLogger" prefix="catalina_log." suffix=".txt" timestamp="true"/>
      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"/>
    </Engine>
  </Service>
</Server>
 
So you have two webapps, and two domains, and you want one domain to map to webapp "1" and another domain to map to webapp "2" ?

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Add to your server.xml two new Host entries.
This assumes you have two webapps, one named webapp1, and one named webapp2, residing in TOMCAT_HOME/webapps.

Example config :

Code:
      <Host name="[URL unfurl="true"]www.domain1.co.uk"[/URL] debug="0" appBase="webapps"
       unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">

        <Valve className="org.apache.catalina.valves.AccessLogValve"
                 directory="logs"  prefix="webapp1_access_log." suffix=".txt"
                 pattern="%h %t  HTTP_REQUEST(%r %s)  REFERER(%{Referer}i)" resolveHosts="false"/>

        <Logger className="org.apache.catalina.logger.FileLogger"
                 directory="logs"  prefix="webapp1_log." suffix=".txt"
            timestamp="true"/>
          <Context path="" docBase="webapp1" debug="0"
                   reloadable="true" crossContext="true"/>
      </Host>

      <Host name="[URL unfurl="true"]www.domain2.co.uk"[/URL] debug="0" appBase="webapps"
       unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">

        <Valve className="org.apache.catalina.valves.AccessLogValve"
                 directory="logs"  prefix="webapp2_access_log." suffix=".txt"
                 pattern="%h %t  HTTP_REQUEST(%r %s)  REFERER(%{Referer}i)" resolveHosts="false"/>

        <Logger className="org.apache.catalina.logger.FileLogger"
                 directory="logs"  prefix="webapp2_log." suffix=".txt"
            timestamp="true"/>
          <Context path="" docBase="webapp2" debug="0"
                   reloadable="true" crossContext="true"/>
      </Host>

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Sedj,
By the time you posted that, I had figured out most of it, but thanks anyway. I have successfully gotten three different webpages to show, one at one at and one at They were simple html files, and for the medivative and aircom sites, I just need to copy the real data in and they should work fine. For Agile, the it is a real application, produced by another company that I am trying to get to work on the server with the other two pages.
My first thought to do this is to make a second context in the host, but this is not working when using the true code. Would I be better off creating a third host to take as it's name instead of two contexts?

Thanks,
Danny
 
No, you would do it like this (assuming you have a webapp named 'agile') :

Code:
      <Host name="[URL unfurl="true"]www.mdediative.com"[/URL] debug="0" appBase="webapps"
       unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">

        <Valve className="org.apache.catalina.valves.AccessLogValve"
                 directory="logs"  prefix="mediative_access_log." suffix=".txt"
                 pattern="%h %t  HTTP_REQUEST(%r %s)  REFERER(%{Referer}i)" resolveHosts="false"/>

        <Logger className="org.apache.catalina.logger.FileLogger"
                 directory="logs"  prefix="mediative_log." suffix=".txt"
            timestamp="true"/>
          <Context path="" docBase="mainwebapp" debug="0"
                   reloadable="true" crossContext="true"/>
          <Context path="/agile" docBase="agile" debug="0"
                   reloadable="true" crossContext="true"/>

      </Host>

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Sedj,

I don't know exactly what I was doing wrong. I had tried that, but it didn't work. Now it does, so I apparently typed something wrong. I am now getting an the following error when I try to go to the webpage. This page worked before using the same J2sdk, so I don't think that is the issue. Any ideas what I need to do?

HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: -1 in the jsp file: null

Generated servlet error:
[javac] Compiling 1 source file

C:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\medivative.com\agile\org\apache\jsp\default_\SystemErrorPage_jsp.java:11: cannot access java.lang.Object
bad class file: C:\Program Files\Java\jre1.5.0_06\lib\rt.jar(java/lang/Object.class)
class file has wrong version 49.0, should be 48.0
Please remove or make sure it appears in the correct subdirectory of the classpath.
public final class SystemErrorPage_jsp extends org.apache.jasper.runtime.HttpJspBase
^
1 error


org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:83)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:315)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:406)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:463)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:442)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:430)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:274)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
com.agilesoft.web.action.ActionServlet.forward(ActionServlet.java:1176)
com.agilesoft.web.action.ActionServlet.forward(ActionServlet.java:1132)
com.agilesoft.web.action.ActionServlet.handleException(ActionServlet.java:706)
com.agilesoft.web.action.ActionServlet.handleRequest(ActionServlet.java:559)
com.agilesoft.hcmServlet.HcmServlet.handleRequest(HcmServlet.java:215)
com.agilesoft.web.action.ActionServlet.doGet(ActionServlet.java:226)
javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)


note The full stack trace of the root cause is available in the Apache Tomcat/5.0.25 logs.


--------------------------------------------------------------------------------

Apache Tomcat/5.0.25
 
Try stopping tomcat, deleting the subdirectories under TOMCAT_HOME/work, and restarting.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top