How to host multiple Jease-Sites within one Tomcat?
The following howto uses Jease as an example, but it is applicable for every web-application which needs to generate pretty urls.
Jease tries really hard to make pretty urls simple. In order to achieve this goal, Jease relies on two concepts:
- Using a smart servlet-filter which can handle content contained within Jease or in the filesystem transparently without the need to add any prefix, extension or parameter. If a ressource can be resolved via Jease, it will be served, otherwise the request will be delegated to be served by Tomcats default handler.
- Jease is deployed as ROOT-application in your application server (e.g. Tomcat), so no additional context-path is added in front of the path.
This works like a charm for one Jease-Instance. But what do you do if you want to run several independent Jease-instances from one physical server?
The simple approach would be to install several application servers on different ports and hide them via a proxy (like Apache)... but that's usually a waste of ressources.
A better approach is to deploy several instances within the same application server... but stop: we already deployed one Jease-instance as ROOT-application in our webapps-folder, so no second instance can take this special position.
But if we want to run independent sites for different domains, we can make use of a concept called "Virtual Hosting". Tomcat is able to serve different applications depending on the requested domain.
For Tomcat this is very easy to configure:
- Create a folder called "sites" in Tomcat (so "sites" and "webapps" are contained within the same directory in the root of your Tomcat-installation).
- Create a subfolder "yourdomain.org" in sites.
- Copy a fresh (or already customized) ROOT.war from a Jease-Installation to "sites/yourdomain.org"
- Now edit Tomcat/conf/server.xml and add a second entry for a new virtual host right below the definition for the default host (which is the first entry below):
... <!-- This entry is already contained in server.xml --> <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false" /> <!-- This entry adds a virtual host for yourdomain.org --> <Host name="yourdomain.org" appBase="sites/yourdomain.org" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false" /> ...
- Now restart Tomcat.
- From now on Tomcat serves all requests for http://yourdomain.org/ from the ROOT-application contained in "sites/yourdomain.org".
This way you can easily add additional sites as well. That's easy, isn't it?