Bootstrap FreeKB - TC Server - Virtual Hosts
TC Server - Virtual Hosts

Updated:   |  TC Server articles

By default, Pivotal TC server is configured with a single host named localhost, which allows Pivotal TC server to send resources to clients from the host named localhost

 

Virtual hosts allows you to configure Pivotal TC server to serve resources to clients from different hostnames.

 

The $CATALINA_HOME/<instance_name>/conf/server.xml file has the host named localhost, which is the defaultHost. The appBase of localhost is webapps, which means that requests to localhost will serve files at and below the $CATALINA_HOME/<instance_name>/ebapps/ directory. By default, the $CATALINA_HOME/webapps/ROOT/index.jsp file will be served.

<Engine defaultHost="localhost" name="Catalina">
. . .
  <Host appBase="webapps"
        autoDeploy="true"
        deployOnStartup="true"
        deployXML="true"
        name="localhost"
        unpackWARs="true">
  . . .
  </Host>

 

Additional virtual hosts can be added. As an example, if your domain name is example.com, one possible sub-domain is stage.example.com. In this scenario, a virtual host named stage.example.com can be added, so that there are now two hosts.

<Engine name="Catalina" defaultHost="localhost">
. . .
  <Host appBase="webapps"
        autoDeploy="true"
        deployOnStartup="true"
        deployXML="true"
        name="localhost"
        unpackWARs="true">
  . . .
  </Host>

  <Host appBase="stage"
        autoDeploy="true"
        deployOnStartup="true"
        deployXML="true"
        name="stage.example.com"
        unpackWARs="true">
  </Host>

 

Stop the server.

[john.doe@server1 ~]$ $CATALINA_HOME/myTCInstance/bin/tcruntime-ctl.sh stop
. . .
Instance shut down gracefully

 

Start the server.

[john.doe@server1 ~]$ $CATALINA_HOME/myTCInstance/bin/tcruntime-ctl.sh start
. . .
Tomcat started.
Status: RUNNING as PID=12345

 


DNS

Configure your DNS server to resolve stage.example.com to the IP address of your Tomcat server.

 


Deploy Application

Since stage.example.com appBase is stage, create the stage directory and the ROOT directory.

[john.doe@server1 ~]# mkdir $CATALINA_HOME/<instance_name>/stage
[john.doe@server1 ~]# mkdir $CATALINA_HOME/<instance_name>/stage/ROOT

 

Add index.jsp to $CATALINA_HOME/stage/ROOT, and then add some text such as Hello World to the index.jsp file.

[john.doe@server1 ~]# touch $CATALINA_HOME/<instance_name>/stage/ROOT/index.jsp

 

You should also be able to navigate to http://stage.example.com:8080 and the index.jsp file should be served.




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter c8a905 in the box below so that we can be sure you are a human.