caucho
Resin
FAQ
Reference Guide
Demo
Tutorial

Getting Started
Configuration
IDE
Topics
JSP
XML/XSLT

Virtual Hosts
Balancing
Distributed Sessions
Caching
JavaScript
Filters
Servlets
Admin
WebDAV
Velocity
EJB Clients
JMX
Burlap
Hessian
 Virtual Hosting

Topics
Topics
Balancing

  1. Standalone Virtual Hosting
  2. Virtual Hosts with Apache or IIS
  3. JVM per Virtual Host
    1. Why the host is necessary
  4. IP-Based Virtual Hosting

Standalone Virtual Hosting

Each Resin instance can serve many virtual hosts. The virtual host will have its own servlets and documents. For greater isolation, you can configure each virtual host to have its own JVM and you can have all the virtual hosts controlled by a single web server.

Configuring the standalone server is the easiest and best way of testing a virtual host configuration. The resin.conf is identical for Resin standalone and for Resin as a servlet runner. So even when using an external web server, it's a good idea to test configuring with Resin standalone.

Each virtual host has its own host block. At very least, each host will define the id specifying the host name and an app-dir to specify the document root.

The following sample configuration defines two virtual hosts, gryffindor and slytherin, each with its own document directory.

resin.conf
<http-server>
  ...

<host id='gryffindor.caucho.com'>
  <app-dir>/home/www/gryffindor/docs</app-dir>
  ...		    
</host>

<host id='slytherin.caucho.com'>
  <app-dir>/home/www/slytherin/docs</app-dir>
  ...		    
</host>

Browsing http://gryffindor.caucho.com/test.jsp will look for /home/www/gryffindor/docs/test.jsp.

Browsing http://slytherin.caucho.com/test.jsp will look for /home/www/slytherin/docs/test.jsp.

Virtual Hosts with Apache or IIS

A common configuration uses virtual hosts with Apache or IIS. As usual, Apache or IIS will pass matching requests to Resin.

The Resin JVM configuration with Apache is identical to the standalone configuration. That similarity makes it easy to debug the Apache configuration by retreating to Resin standalone if needed.

The ServerName directive in Apache is vital to make Resin's virtual hosting work. When Apache passes the request to Resin, it tells Resin the ServerName. Without the ServerName, Resin can get very confused which host to serve.

httpd.conf
LoadModule caucho_module /usr/local/apache/libexec/mod_caucho.so
AddModule mod_caucho.c

CauchoConfigFile /home/www/conf/resin.conf

<VirtualHost 127.0.0.1>
  ServerName gryffindor.caucho.com
</VirtualHost>

<VirtualHost 192.168.0.1>
  ServerName slytherin.caucho.com
</VirtualHost>

Note: You'll the LoadModule and AddModule must appear before the CauchoConfigFile for Apache to properly understand the CauchoConfigFile command. If they're missing, Apache will send an error.

JVM per Virtual Host

In some ISP setups, it may make sense to assign a JVM for each virtual host. The isolation of web-apps may not be sufficient; each user needs a separate JVM. In this configuration, each JVM needs its own srun-port and possibly its own srun-host.

In the most straightforward configuration, each JVM gets its own resin.conf. The resin.conf can use resin:include to share common configuration.

httpd.conf
<VirtualHost 127.0.0.1>
  ServerName gryffindor.caucho.com
  CauchoConfigFile /home/www/config/gryffindor.conf
</VirtualHost>

<VirtualHost 192.168.0.1>
  ServerName slytherin.caucho.com
  CauchoConfigFile /home/www/config/slytherin.conf
</VirtualHost>

Here's the corresponding gryffindor.conf

gryffindor.conf
<caucho.com>
<http-server>
  <srun host=localhost port=8910/>

  <host id='www.gryffindor.com'>
    <app-dir>/home/www/gryffindor/htdocs</app-dir>

    <resin:include href='common.conf'/>
  </host>
</http-server>
</caucho.com>
slytherin.conf
<caucho.com>
<http-server>
  <srun host=localhost port=8911/>

  <host id='www.slytherin.com'>
    <app-dir>/home/www/slytherin/htdocs</app-dir>

    <resin:include href='common.conf'/>
  </host>
</http-server>
</caucho.com>

You'll start each JVM separately. With Unix, you might do something like:

unix> bin/httpd.sh -conf gryffindor.conf -pid gryffindor.pid start
unix> bin/httpd.sh -conf slytherin.conf -pid slytherin.pid start

On Unix, the -pid will let resin know which server to stop.

unix> bin/httpd.sh -conf gryffindor.conf -pid gryffindor.pid stop
unix> bin/httpd.sh -conf slytherin.conf -pid slytherin.pid stop

When you restart the web server, you can look at http://gryffindor/caucho-status and http://slytherin/caucho-status to check your configuration. Check that each virtual host is using the srun-host and srun-port that you expect.

Why the host is necessary

The <host> block in gryffindor.conf and slytherin.conf is required for a subtle reason. When Resin compiles JSP files, it generates a Java class name. Classes for different hosts get different class names to prevent name collisions.

If gryffindor.conf and slytherin.conf omit the <host>, Resin will generate the same class name for both hosts. If both hosts also use the same work-dir, one host will see the JSP for the other host.

IP-Based Virtual Hosting

While Resin's virtual hosting is primarily aimed at named-based virtual hosts, it's possible to run Resin with IP-Based virtual hosts.

With IP virtual hosting, each <http> block is configured with the virtual host name. This configuration will override any virtual host supplied by the browser.

<http-server>
  <http host='192.168.0.1' port='80'
        virtual-host='slytherin.caucho.com'/>

  ...

  <host id='slytherin.caucho.com'>
    ...
  </host>
</http-server>


Topics
Topics
Balancing
Copyright © 1998-2002 Caucho Technology, Inc. All rights reserved.
Resin® is a registered trademark, and HardCoretm and Quercustm are trademarks of Caucho Technology, Inc.