resin.conf and host element

By abhirama

Understanding the host element in resin.conf file. Let us take the below element as an example:

<host id=’*'>
<root-directory>./foo</root-directory>
<web-app id=”/”>
<document-directory>webapps/foo</document-directory>
</web-app>
</host>

Let us dissect this one by one:

1. <host id=’*'>

This lets you specify the host name for which this web application is applicable. Putting a * means that it is applicable for all requests that you redirect to the port resin is listening on irrespective of their urls.

If the host id is as below

<host id=’foo.com’>

Then it is applicable only to those requests looking for foo.com (Assuming you have configured the hosts.conf file to redirect requests for foo.com to the port your local resin is listening on).

Host id is the way to host multiple applications within a single resin instance. We will look at hosting multiple applications at the end.

2.  <root-directory>./foo</root-directory>

The present directory for this is the resin home folder .

For example if your application is in the webapps folder of the home directory then root directory would be just

<root-directory>.</root-directory>

If your webapps is  in some other folder say foo then your root directory would be

<root-directory>./foo</root-directory>

3. <document-directory>webapps/foo</document-directory>

This takes off where the  root-directory left off. The path in the document-directory will be appended to the root-directory.

So for the snippet above the absolute path of the document directory will be as below:

${resin.home}/webapps/foo

So for an application with the directory structure as below

${resin.home}/bar/webapps/foo

root-directory will be

<root-directory>./bar</root-directory>

and  document-directory will be

<document-directory>webapps/foo </document-directory>

4. web-app id=”/”

This is the beginning part of the URI that should be appended to the URL to access pages on this web application. For example if the url is www.foo.com and your id is

web-app id=”bar”

Then to view the index page the URL would look as http://www.foo.com/bar/index.html

If the web app id is web-app id=”/” then the above link will be http://www.foo.com/index.html

Now to the part where we want to host multiple web applications within one resin instance:

<host id=’foo.com’>
<root-directory>./foo</root-directory>
<web-app id=”/”>
<document-directory>webapps/foo</document-directory>
</web-app>
</host>

<host id=’bar.com’>
<root-directory>.</root-directory>
<web-app id=”/”>
<document-directory>webapps/foo</document-directory>
</web-app>
</host>

The directory structure of the above application will be:

1. ${resin.home}/foo/webapps/foo

2. ${resin.home}/webapps/bar

I do not know as to whether it is possible to host 2 web applications within the same webapps folder. I tried doing it and I got an InstanceAlreadyExistsException on my windows box. If someone knows the way to do it please enlighten me.

Disclaimer :  I am not a resin expert.  The knowledge  I have gained comes from playing around with resin  yesterday night for about an hour. Even though I have been using resin for the past 7 months I never had to configure anything until yesterday. If there are any errors please notify me and I will update it accordingly.

Leave a Reply