May 2014

Gavin Pickin

Multi CFML Engine Install - Editing Server.XML for Tomcat VHosts

CFML Server, Server Admin

To make editing your Server.xml easier, I'm going to show you a trick, so you can include another file, into your server.xml, so you can add Virtual Hosts (or other settings if you like) so you dont have to edit your Server.XML file so often. This can be useful for automation, or just locking down certain pieces of the server.xml, or just convenience.

If you have followed along, in other Linux Installs, I have put my Web files in /home/www but you can put them wherever you like. I like to keep them all together, so _settings in my websites folder holds various settings on and config files... this is no different.

Added a folder for settings /home/www/_settings
Inside there, create a file, and then we will setup the server.xml file to include this file

nano railoa-tc-vhosts.xml

Put this in the file

<Host name="" appBase="webapps">
        <Context path="" docBase="/opt/railoa/tomcat/webapps/ROOT" />
<Host name="localhost" appBase="webapps">
        <Context path="" docBase="/opt/railoa/tomcat/webapps/ROOT" />

[ Enter ]

Adding the Magic to include the file into your Server.xml

Go back to server.xml in /opt/railoa/tomcat/conf/server.xml

Edit the top of the file so it looks like this

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE server-xml [
  <!ENTITY vhosts-config SYSTEM "file:///home/www/_settings/railoa-tc-vhosts.xml">

What we have done, is created a variable, called vhosts-config, and we have loaded the contents of the System file, into that variable. Now, we just need to output that variable, into the server.xml where we want it.

Update our Server.xml's default host

At the start of the Engine definition, the default host is defined.
    <Engine name="Catalina" defaultHost="">

So the host record will be the default.
Lets update the host record in this file, so it doesn't match, and the vhost record we just created will be the default host.

Go down to the middle of the file, where you see the First Host record, for
This looks like this

      <Host name=""  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

To deactivate this Host record, so you can control everything through our vhosts file, update the ip, to something else, like

      <Host name=""  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

Below that host entry is a another host, for localhost.
I comment that out, so we can control everything from vhosts.

      <Host name="localhost" appBase="webapps">
        <Context path="" docBase="/opt/railoa/tomcat/webapps/ROOT/" />

Adding the vhosts-config variable into the server.xml Page

Go down to the bottom of the fileā€¦ and right above the SAMPLE VHOSTS

insert &vhosts-config; so it looks like this


        <Host name="[ENTER DOMAIN NAME]" appBase="webapps">
             <Context path="" docBase="[ENTER SYSTEM PATH]" />
             <Alias>[ENTER DOMAIN ALIAS]</Alias>


Now, we can programmatically alter the vhosts.xml file, giving permissions to those files, without compromising our main server.xml file.

Multiple Railo Instances

If you have a multiple Railo Instance setup, you can copy the railoa-tc-vhosts.xml to b and c, and update the internals accordingly.
Go back and edit the server.xml as described above, and all railo server.xml files will be setup to allow us to easily add and remove hosts as needed.

If you are running a cluster of multiple Railo Instances on the same box, they can all include the same vhosts.xml so you don't have to update it for each instance, another advantage of this approach.

Remember, Tomcat needs to restart whenever you change your configuration.

Hope this helps.





Blog Search