caucho
Resin 1.1
FAQ
Reference
JavaDoc
Demo
Java Tutorial

Getting Started
Configuration
Servlet
JSP
XTP/XSL
JavaScript
JS Library

Resin Config
HTTP Config
App Config
Servlet Config
Login Config
Taglib Config
Virtual Hosts
Caching
 Virtual Hosting

  1. httpd virtual hosting
  2. Virtual Hosts with Apache
  3. JVM per Virtual Host

httpd virtual hosting

As usual, configuring the standalone server is the easiest and best way of testing a virtual host configuration.

Virtual hosting in Resin is based on the Host: header in the HTTP request. When a browser contacts a site, it tells the site the host name typed into the request. This means that a site can serve several virtual hosts with the same IP address.

The following sample configuration defines two virtual hosts using different application directories.

<http-server>
  ...

<host id='gryffindor.caucho.com'>
  <app-dir>/home/www/gryffindor/docs<app-dir>
  <servlet-mapping url-pattern='/servlet/*'
                   servlet-name='invoker'/>
  ...     
</host>

<host id='slytherin.caucho.com'>
  <app-dir>/home/www/slytherin/docs<app-dir>
  <servlet-mapping url-pattern='/servlet/*'
                   servlet-name='invoker'/>
  ...     
</host>

Virtual Hosts with Apache

A more common configuration uses virtual hosts with Apache. Apache is better able to handle IP-based virtual hosting. (Getting the IP-address from Java is embarassingly slow.)

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.

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

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

JVM per Virtual Host

In some ISP setups, it may make sense to assign a JVM for each virtual host. In some cases, the isolation of web-apps is not 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.

<VirtualHost 127.0.0.1>
  ServerName gryffindor.caucho.com
  CauchoConfigFile /home/www/gryffindor/resin.conf
  CauchoHost localhost 8910
</VirtualHost>

<VirtualHost 192.168.0.1>
  ServerName slytherin.caucho.com
  CauchoConfigFile /home/www/slytherin/resin.conf
  CauchoHost localhost 8911
</VirtualHost>

Here's the corresponding gryffindor resin.conf

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

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

In an alternate configuration, the JVMs can share the same resin.conf, each with a host block, but each listens to a different port.

<VirtualHost 127.0.0.1>
  ServerName gryffindor.caucho.com
  CauchoConfigFile /home/www/conf/resin.conf
  CauchoHost localhost 8910
</VirtualHost>

<VirtualHost 192.168.0.1>
  ServerName slytherin.caucho.com
  CauchoConfigFile /home/www/conf/resin.conf
  CauchoHost localhost 8911
</VirtualHost>

The resin.conf is identical to the resin.conf at the top of this page.

You'll need to start the server with -port 8910 to give the server it's own port.


Taglib Config   Caching
Copyright © 1998-2000 Caucho Technology. All rights reserved.
Last modified: Thu, 30 Mar 2000 14:47:50 -0800 (PST)