Caucho Technology
  • resin 4.0
  • virtual hosting


    A Resin server can serve many virtual hosts, each with its own servlets and documents. The configuration is flexible, allowing dynamic host deployment in a hosts directory or using explicit <host> tags for additional control and security, and compatibility with existing Apache sites, enabling easy upgrades and evaluation for PHP servers to Quercus.

    Overview

    Virtual hosts are multiple internet domains served by the same Resin server. Because one JVM handles all the domains, its more memory and processing efficient, as well as sharing IP addresses. With Resin, adding virtual hosts can as easy as creating a directory like /var/www/hosts/foo.com and setting up the DNS name. Explicit virtual host is also possible to match existing layouts, like matching a /var/www/htdocs configuration when migrating a PHP mediawiki or wordpress site to use Quercus for security and performance.

    The virtual host will contain one or more web-apps to serve the host's contents. Simple sites will use a fixed root webapp, like the Apache-style /var/www/htdocs. More complicated sites can use a webapps-style directory.

    Each virtual host belongs to a Resin <cluster>, even if the cluster has only a single server.

    For example, a Resin server might manage both the www.gryffindor.com and www.slytherin.com domains, storing the content in separate directories (/var/www/gryffindor and /var/www/slytherin), and using a single IP address for both domains. In this scenario, both www.gryffindor.com and www.slytherin.com are registered with the standard domain name service registry as having the IP address 192.168.0.13. When a user types in the url http://www.gryffindor.com/hello.jsp in their browser, the browser will send the HTTP request to the IP address 192.168.0.13 and send an additional HTTP header for the gryffindor host, "Host: www.gryffindor.com". When Resin receives the request it will grab the host header, and dispatch the request to the configured virtual host.

    Example: HTTP request headers
    C: GET /test.jsp HTTP/1.1
    C: Host: www.gryffindor.com
    C:
    
    1. host name
    2. host aliases
    3. optional host.xml
    4. root directory
    5. web-applications
    6. configuration environment
    7. logging

    Dynamic virtual hosts

    Resin can deploy virtual hosts automatically by scanning a host deployment directory for virtual host content. Each sub-directory in the hosts directory will cause Resin to create a new virtual host. To customize the configuration, you can add a host.xml in the host's root directory for shared databases, beans or security, or to add <host-alias> names.

    You can add hosts dynamically to a running server just by creating a new host directory. Resin periodically scans the hosts directory looking for directory changes. When it detects a new host directory, it will automatically start serving files from the new virtual hosts.

    If you add a default directory in the hosts, Resin will use it to serve all unknown virtual hosts. The default host is handy for simple servers with only a single virtual host and for sites where the virtual host is handled in software, like Drupal. If the default directory is missing, Resin will return 404 Not Found for any unknown virtual hosts.

    Example: virtual host directory structure
    /var/www/hosts/www.gryffindor.com/
                                     host.xml
                                     log/access.log
                                     webapps/ROOT/index.jsp
                                     webapps/ROOT/WEB-INF/resin-web.xml
    				 
    /var/www/hosts/www.slytherin.com/
                                    host.xml
                                    log/access.log
                                    webapps/ROOT/index.php
                                    webapps/ROOT/WEB-INF/resin-web.xml
    				 
    /var/www/hosts/default/
                          host.xml
                          log/access.log
                          webapps/ROOT/index.php
                          webapps/ROOT/WEB-INF/resin-web.xml
    
    

    host-aliasing for dynamic hosts

    Often, the same virtual host will respond to multiple names, like www.slytherin.com and slytherin.com. One name is the primary name and the others are aliases. In Resin, the primary name is configured by the <host-name> tag and aliases are configured by <host-alias>. In a dynamic host configuration, the directory name is used as the host-name by default, and aliases are declared in the host.xml.

    Example: www.slytherin.com/host.xml
    <host xmlns="http://caucho.com/ns/resin">
      <host-name>www.slytherin.com</host-name>
      <host-alias>slytherin.com</host-alias>
      <host-alias>quidditch.slytherin.com</host-alias>
    </host>
    

    Since the host.xml is shared for all web-applications in the host, you can also use it to configure shared resources like security logins, shared databases, and shared resources.

    host-deploy configuration

    The <host-deploy> tag configures the dynamic virtual hosting specifying the directory where Resin should scan for virtual hosts. Because Resin does not automatically add default configuration, you will need to also add configuration for the host.xml, app-default.xml and web-app-deploy. Although it's a bit more verbose, the no-default rule makes Resin more secure and debuggable. If an item like a <web-app> is missing, Resin will return 404 Not Found for security. Because all configuration is explicit, it's ultimately traceable to the resin.xml which makes debugging more reliable.

    Shared host configuration goes in the <host-default> tag. In this case, we've added an optional host.xml for configuration, an access log in log/access.log and a standard webapps directory. The standard servlets and file handling come from the app-default.xml file. If you omit either the app-default.xml or the webapps, you will see 404 Not Found for any requests.

    The example below is a complete, working resin.xml listening to HTTP at port 8080. The cluster consists of a single server. It includes a <development-mode-error-page> to help debugging the configuration. Many sites will omit the error-page to hide configuration details in case an error occurs on a live site.

    Example: /etc/resin/resin.xml host-deploy configuration
    <resin xmlns="http://caucho.com/ns/resin"
              xmlns:resin="urn:java:com.caucho.resin">
    <cluster id="app-tier">
      <server id="app-a" address="192.168.1.13" port="6800">
        <http port="8080"/>
      </server>
    
      <development-mode-error-page/>
    
      <resin:import path="${__DIR__}/app-default.xml"/>
      
      <host-default>
        <resin:import path="host.xml" optional="true"/>
    
        <access-log path="log/access.log"/>
    	
        <web-app-deploy path="webapps"/>
      </host-default>
    
      <host-deploy path="hosts">
      </host-deploy>
      
    </cluster>
    </resin>
    

    Any directory created in ${resin.root}/hosts will now become a virtual host. You can also place a .jar file in ${resin.root}/hosts, it is expanded to become a virtual host.

    ${resin.root}/hosts/www.gryffindor.com/
    ${resin.root}/hosts/www.gryffindor.com/webapps/ROOT/index.jsp
    ${resin.root}/hosts/www.gryffindor.com/webapps/foo/index.jsp
    
    ${resin.root}/hosts/www.slytherin.com.jar
    

    Jar libraries and class files that are shared amongst all webapps in the host can be placed in lib and classes subdirectories of the host:

    ${resin.root}/hosts/www.gryffindor.com/lib/mysql-connector-java-3.1.0-alpha-bin.jar 
    ${resin.root}/hosts/www.gryffindor.com/classes/example/CustomAuthenticator.java
    

    More information is available in the configuration documentation for <host-deploy> and <host-default>.

    Explicit Virtual Hosting

    In a more structured site, you can take complete control of the virtual host configuration and configure each virtual host explicitly. Existing sites wanting to upgrade to Resin or sites with extra security needs may prefer to configure each <host> in the resin.xml. For example, a PHP Drupal site evaluating Quercus to improve performance and security might use the explicit <host> to point to the existing /var/www/htdocs directory.

    In the explicit configuration, each virtual host has its own host block. At the very least, each host will define the id specifying the host name and a root web-app. A root-directory is often used to provide a host specific root for logfiles.

    As with the dynamic hosting, servlets and web-apps must be configured either in a <host-default> or explicitly. If they are missing, Resin will return a 404 Not Found for security. The host id="" is the default host and will serve any request that doesn't match other hosts. If you don't have a default host, Resin will return a 404 Not Found for any unknown host.

    The following sample configuration defines an explicit virtual hosts www.slytherin.com and a default host, each with its own root directory, access-log and a single explicit <web-app> in the htdocs directory. The default virtual host is configured just like a typical Apache configuration, so it can be used to upgrade an Apache/PHP site to use Quercus for security and performance.

    Example: /etc/resin/resin.xml
    <resin xmlns="http://caucho.com/ns/resin"
            xmlns:resin="urn:java:com.caucho.resin">
            
    <cluster id="app-tier">
      <server id="app-a" address="192.168.1.10" port="6800">
        <http port="8080"/>
      </server>
    
      <development-mode-error-page/>
    
      <resin:import path="${__DIR__}/app-default.xml"/>
    
      <host id="">
        <root-directory>/var/www</root-directory>
    
        <access-log path="logs/access.log"/>
    
        <web-app id="" root-directory="htdocs"/>
      </host>
    
      <host id="www.slytherin.com">
        <host-alias>slytherin.com</host-alias>
        
        <root-directory>/var/slytherin</root-directory>
    
        <access-log path="logs/access.log"/>
    
        <web-app id="" root-directory="htdocs"/>
      </host>
    
    </cluster>
    </resin>
    

    Browsing http://gryffindor.caucho.com/test.php will look for /var/www/htdocs/test.php.

    Browsing http://slytherin.caucho.com/test.php will look for /var/slytherin/htdocs/test.php.

    Server per virtual host

    In some ISP setups, it may make sense to assign a server for each virtual host. The isolation of web-apps may not be sufficient; each host needs a separate JVM. In this configuration, each <host> belongs to its own <cluster> and has a dedicated <server>. Normally, this configuration will operate using load-balancing, so the load-balance server will dispatch requests as appropriate.

    For further security restrictions, see the watchdog section. ISPs can also use the watchdog to assign different <user-name> values for each host and can even create chroot directories for each JVM.

    A front-end web server receives all requests, and is configured to dispatch to back-end Resin server that correspond to the host name.

    Back-end JVMs

    Each host is placed in its own <cluster> with a dedicated <server>. Since the server listens to a TCP port for load-balancing and clustering messages, each server on the maching needs a different server port.

    In this example, the virtual hosts www.gryffindor.com and www.slytherin.com each get their own server. The backend clusters have their own virtual host. The frontend load-balancer dispatches the <resin:LoadBalance> tags to the backend.

    This example is split into two blocks to emphasize the frontend and backend. Typically, they will both actually be in the same resin.xml to ensure consistency.

    Example: /etc/resin/resin.xml for backend
    <resin xmlns="http://caucho.com/ns/resin"
              xmlns:resin="urn:java:com.caucho.resin">
    
      <cluster-default>
        <resin:import path="${resin.home}/conf/app-default.xml"/>
        
        <host-default>
          <web-app-deploy path="webapps"/>
        </host-default>
      </cluster-default>
    
      <cluster id="gryffindor>
        <server id="gryffindor" host="localhost" port="6800"/>
    
        <host id="www.gryffindor.com">
      
          <root-directory>/var/www/gryffindor</root-directory>
    
        </host>
      </cluster>
    
      <cluster id="slytherin">
        <server id="slytherin" host="localhost" port="6801"/>
    
        <host id="www.slytherin.com">
      
          <root-directory>/var/www/slytherin</root-directory>
    
        </host>
      </cluster>
    
      <cluster id="web-tier">
        <!-- see below -->
        ...
      </cluster>
    
    </resin>
    

    Each back-end server is started separately:

    Example: starting backend servers
    unix> java -jar lib/resin.jar -server gryffindor start
    unix> java -jar lib/resin.jar -server slytherin start
    
    Example: stopping backend servers
    unix> java -jar lib/resin.jar -server gryffindor stop
    unix> java -jar lib/resin.jar -server slytherin stop
    

    Resin web-tier load balancer

    The host-specific back-end servers are ready to receive requests on their server ports. A third Resin server can be used as the front-end load-balancer. It receives all requests and dispatches to the back-end servers.

    The Resin web server is configured using rewrite with a <resin:LoadBalance directive to dispatch to the back-end server. A cluster is defined for each back-end host, so that the <load-balance> knows how to find them.

    Example: /etc/resin/resin.xml for front-end web server
    <resin xmlns="http://caucho.com/ns/resin"
         xmlns:resin="urn:java:com.caucho.resin">
         
      <cluster id="web-tier">
        <server-default>
          <http port="80"/>
        </server-default>
    
        <server id="web" address="192.168.2.1" port="6800"/>
    
        <host id="gryffindor.com">
          <web-app id="/">
    
            <resin:LoadBalance regexp="" cluster="gryffindor"/>
    
          </web-app>
        </host>
    
        <host id="slytherin.com">
          <web-app id="/">
    
            <resin:LoadBalance regexp="" cluster="slytherin"/>
    
          </web-app>
        </host>
      </cluster>
    
      <cluster id="gryffindor">
        <server id="gryffindor" address="192.168.2.2" port="6800"/>
    
        <host id="www.gryffindor.com">
          ...
        </host>
      </cluster>
    
      <cluster id="slytherin">
        <server id="slytherin" address="192.168.2.2" port="6801"/>
    
        ...
      </cluster>
    </resin>
    

    Starting the servers on Unix

    The front-end server JVM is started similar to the back-end JVMs:

    Example: starting the load balancer
    unix> java -jar lib/resin.jar -server web -conf conf/resin.xml start
    ...
    unix> java -jar lib/resin.jar -server web -conf conf/resin.xml stop
    

    Starting the servers on Windows

    With Windows, each JVM is installed as a service. Service is installed using setup.exe graphical utility. It's possible to install a number of Resin services each using a unique name. The name will need to be supplied into 'Service Name' field.

    You will either need to reboot the machine or start the service from the Control Panel/Services panel to start the server. On a machine reboot, NT will automatically start the service.

    There is a bug in many JDKs which cause the JDK to exit when the administrator logs out. JDK 1.4 and later can avoid that bug if the JDK is started with -Xrs.

    Configuration tasks

    host naming

    The virtual host name can be configured by an explicit <host-name>, a <host-alias>, a <host-alias-regexp>, by the <host> tag or implicitly by the <host-deploy>. For explicit configuration styles, the host name and alias configuration will generally be in the resin.xml. For dynamic configuration, the host aliases will typically be in an included host.xml inside the host directory.

    The default host catches all unmatches hosts. Simpler sites will use the default host for all requests, while security-conscious sites may remove the default host entirely. If the default host is not configured, Resin will return a 404 Not Found.

    host.xml

    The host.xml is an optional file where virtual hosts can put host-common configuration. The host.xml is a good place for shared resources like authentication, database pools or host-wide beans and services. It's also a location for the <host-alias> in a dynamic hosting configuration.

    The host.xml is configured in a <host-deploy> or <host-default> by adding a <resin:import> tag specifying the host.xml name and location. Because the <host-default> applies the <resin:import> to every virtual host, it becomes a common system-wide configuration file.

    web-applications

    Hosts must define web-apps in order to serve files, servlets, or PHP pages. If the host is missing all webapps, Resin will return 404 Not Found for all requests make to the host.

    Both explicit <web-app> and dynamic web-app-deploy tags are used to configure webapps. The explicit style is generally used for Apache-style configuration, while the dynamic style is generally used for Java app-server .war configuration.

    Remember, Resin's default servlets like the file, JSP, and PHP servlets also need to be defined before they're used. So all Resin configuration files need to have a <resin:import> of the conf/app-default.xml configuration file either in the <cluster> or in a shared <cluster-default>. If the app-default.xml is missing, Resin will not serve static files, JSP, or PHP, and will not even look in the WEB-INF for resin-web.xml, classes, or lib.

    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.

    <resin xmlns="http://caucho.com/ns/resin">
    
    <cluster id="web-tier">
      <server id="a">
    
        <http address="192.168.0.1" port="80"
              virtual-host="slytherin.caucho.com"/>
    
        <http address="192.168.0.2" port="80"
              virtual-host="gryffindor.caucho.com"/>
    
      </server>
    
      ...
    
      <host id="slytherin.caucho.com">
        ...
      </host>
    </cluster>
    </resin>
    

    Internationalization

    Resin's virtual hosting understands host names encoded using rfc3490 (Internationalizing Domain Names in Applications). This support should be transparent. Just specify the virtual host as usual, and Resin will translate the brower's encoded host name the unicode string.

    Support, of course, depends on the browser. Mozilla 1.4 supports the encoding.

    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.

    Apache

    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 with the UseCanonicalName can be used to select a canonical name for the virtual host virtual hosting work. When Apache passes the request to Resin, it tells Resin the ServerName. Without the ServerName, Apache will use the "Host:" header in the HTTP request to select which host to serve.

    httpd.conf
    LoadModule caucho_module /usr/local/apache/libexec/mod_caucho.so
    
    ResinConfigServer localhost 6802
    
    UseCanonicalName on
    
    <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 must appear before the ResinConfigServer for Apache to properly understand the ResinConfigServer command. If they're missing, Apache will send an error.

    Apache front-end

    The host-specific back-end JVMs are ready to receive requests on their server ports. Apache is the front-end server, and is configured to dispatch to the appropriate back-end Resin JVM for the host:

    httpd.conf
    UseCanonicalName on
    
    <VirtualHost 127.0.0.1>
      ServerName gryffindor.caucho.com
      ResinConfigServer 192.168.0.10 6800
    </VirtualHost>
    
    <VirtualHost 192.168.0.1>
      ServerName slytherin.caucho.com
      ResinConfigServer 192.168.0.11 6800
    </VirtualHost>
    

    When you restart the Apache 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 server address and port that you expect.

    Testing virtual hosts

    During development and testing, it is often inconvenient or impossible to use real virtual host names that are registered as internet sites, and resolve to an internet-available IP address. OS-level features on the test client machine can be used to map a virtual host name to an IP address.

    For example, developers often run the Resin server and the test client (usually a browser) on the same machine. The OS is configured to map the "www.gryffindor.com" and "www.slytherin.com" names to "127.0.0.1", pointing these host names back to computer that the client is running on.

    Unix users edit the file /etc/hosts:

    /etc/hosts
    127.0.0.1       localhost
    
    127.0.0.1       www.gryffindor.com
    127.0.0.1       www.slytherin.com
    

    Windows user edit the file C:\WINDOWS\SYSTEM32\DRIVERS\ETC\HOSTS:

    C:\WINDOWS\SYSTEM32\DRIVERS\ETC\HOSTS
    127.0.0.1       localhost
    
    127.0.0.1       www.gryffindor.com
    127.0.0.1       www.slytherin.com
    

    <access-log>

    <access-log> configures the access log file.

    As a child of web-app, overrides the definition in the host that the web-app is deployed in. As a child of host, overrides the definition in the server that the host is in.

    The default archive format is

    path + ".%Y%m%d" or
      path + ".%Y%m%d.%H" if rollover-period < 1 day.
    

    The access log formatting variables follow the Apache variables:

    format patterns
    PATTERNDESCRIPTION
    %bresult content length
    %Dtime taken to complete the request in microseconds (since 3.0.16)
    %hremote IP addr
    %{xxx}irequest header xxx
    %{xxx}oresponse header xxx
    %{xxx}ccookie value xxx
    %nrequest attribute
    %rrequest URL
    %sstatus code
    %Srequested session id
    %{xxx}trequest date with optional time format string.
    %Ttime taken to complete the request in seconds
    %uremote user
    %Urequest URI
    %vname of the virtual host serving the request

    The default format is:

    default access log format
    "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""
    

    resin:type allows for custom logging. Applications can extend a custom class from com.caucho.http.log.AccessLog. Resin-IoC initialization can be used to set bean parameters in the custom class.

    <access-log> Attributes
    ATTRIBUTEDESCRIPTIONDEFAULT
    pathOutput path for the log entries, see "Log Paths".required
    path-formatSelects a format for generating path names. The syntax is the same as for archive-format.optional
    archive-formatthe format for the archive filename when a rollover occurs, see Rollovers. see below
    auto-flushtrue to flush the memory buffer with each request. false
    auto-flush-timesets time interval for flushing the memory buffers 60s
    excludeaccess logging exclude patterns for request URIs. Access to matching URIs does not get logged.none
    formatAccess log format.see above
    hostname-dns-lookuplog the dns name instead of the IP address (has a performance hit).false
    rollover-periodhow often to rollover the log. Specify in days (15D), weeks (2W), months (1M), or hours (1h). See "Rollovers". none
    rollover-sizemaximum size of the file before a rollover occurs, in bytes (50000), kb (128kb), or megabytes (10mb). See "Rollovers". 1mb
    rollover-countmaximum number of rollover files before the oldest ones get overwritten. See "Rollovers". 1mb
    resin:typea class extending com.caucho.server.log.AccessLog for custom logging com.caucho.server.log.AccessLog
    initResin-IoC initialization for the custom classn/a
    <access-log> schema
    element access-log {
      path?
      & path-format?
      & archive-format?
      $amp;auto-flush?
      & auto-flush-time?
      & exclude*
      & format?
      & hostname-dns-lookup?
      & rollover-period?
      & rollover-size?
      & rollover-count?
      & resin:type?
      & init?
    }
    
    Example: <access-log> in host configuration
    <resin xmlns="http://caucho.com/ns/resin">
    <cluster id="app-tier">
    
      <host id="">
        <access-log path='log/access.log'>
          <rollover-period>2W</rollover-period>
        </access-log>
      </host>
    </cluster>
    </resin>
    
    Example: custom access log
    <resin xmlns="http://caucho.com/ns/resin">
    
    <cluster id="app-tier">
    
      <host id='foo.com'>
    
        <access-log>
          <test:MyLog xmlns:test="urn:java:test">
                     path='${resin.root}/foo/error.log'
                     rollover-period='1W'>
              <test:foo>bar</test:foo>
          </test:MyLog>
        </access-log>
        ...
      </host>
    
    </cluster>
    </resin>
    

    <ear-deploy>

    child of host,web-app

    Specifies ear expansion.

    ear-deploy can be used in web-apps to define a subdirectory for ear expansion.

    <ear-deploy> Attributes
    ATTRIBUTEDESCRIPTIONDEFAULT
    archive-pathThe path to the directory containing ear filespath
    ear-defaultresin.xml default configuration for all ear files, e.g. configuring database, JMS or EJB defaults.
    expand-cleanup-filesetSpecifies the files which should be automatically deleted when a new .ear version is deployed.
    expand-directorydirectory where ears should be expandedvalue of path
    expand-prefixautomatic prefix of the expanded directory_ear_
    expand-suffixautomatic suffix of the expanded directory
    lazy-initif true, the ear file is only started on first accessfalse
    pathThe path to the deploy directoryrequired
    redeploy-mode"automatic" or "manual". If automatic, detects new .ear files automatically and deploys them.automatic
    url-prefixoptional URL prefix to group deployed .ear files
    <ear-deploy> schema
    element ear-deploy {
      path
      & archive-directory?
      & ear-default?
      & expand-cleanup-fileset?
      & expand-directory?
      & expand-path?
      & expand-prefix?
      & expand-suffix?
      & lazy-init?
      & redeploy-mode?
      & require-file*
      & url-prefix?
    }
    

    <error-page>

    <error-page> defines a web page to be displayed when an error occurs outside of a web-app. Note, this is not a default error-page, i.e. if an error occurs inside of a <web-app>, the error-page for that web-app will be used instead.

    See webapp: error-page.

    <host>

    child of cluster

    <host> configures a virtual host. Virtual hosts must be configured explicitly.

    <host> Attributes
    ATTRIBUTEDESCRIPTIONDEFAULT
    idprimary host namenone
    regexpRegular expression based host matchingnone
    host-nameCanonical host namenone
    host-aliasAliases matching the same hostnone
    secure-host-nameHost to use for a redirect to SSLnone
    root-directoryRoot directory for host filesparent directory
    startup-mode'automatic', 'lazy', or 'manual', see startup-modeautomatic
    Example: explicit host in resin.xml
    <resin xmlns="http://caucho.com/ns/resin">
    <cluster id="">
    
    <host host-name="www.foo.com">
      <host-alias>foo.com</host-alias>
      <host-alias>web.foo.com</host-alias>
    
      <root-directory>/opt/www/www.foo.com</root-directory>
    
      <web-app id="/" document-directory="webapps/ROOT">
        
      </web-app>
      ...
    </host>
    
    </cluster>
    </resin>
    
    Example: regexp host in resin.xml
    <resin xmlns="http://caucho.com/ns/resin">
    <cluster id="">
    
    <host regexp="([^.]+)\.foo\.com">
      <host-name>${host.regexp[1]}.foo.com</host-name>
    
      <root-directory>/var/www/hosts/www.${host.regexp[1]}.com</root-directory>
    
      ...
    </host>
    
    </cluster>
    </resin>
    

    It is recommended that any <host> using a regexp include a <host-name> to set the canonical name for the host.

    <host-alias>

    <host-alias> defines a URL alias for matching HTTP requests. Any number of <host-alias> can be used for each alias.

    The host-alias can be used either in the resin.xml or in a host.xml when use host-deploy together with resin:import.

    <host-alias> schema
    element host-alias {
      string
    }
    
    Example: host-alias in the resin.xml
    <resin xmlns="http://caucho.com">
    <cluster id="">
    
      <host id="www.foo.com" root-directory="/var/www/foo.com">
        <host-alias>foo.com</host-alias>
    
        <web-app id=""/>
      </host>
    
    </cluster>
    </resin>
    

    Since the <host-deploy> and <host> tags lets you add a host.xml file to customize configuration, the <host-alias> can also fit in the custom host.xml page.

    Example: host-alias in a /var/www/hosts/foo/host.xml
    <host xmlns="http://caucho.com">
    
      <host-name>www.foo.com</host-name>
      <host-alias>foo.com</host-alias>
    
      <web-app id="" root-directory="htdocs"/>
    
    </host>
    

    <host-alias-regexp>

    <host-alias-regexp> defines a regular expression for matching URLs for a given virtual host.

    <host-alias-regexp> schema
    element host-alias-regexp {
      string
    }
    
    Example: host-alias-regexp in the resin.xml
    <resin xmlns="http://caucho.com">
    <cluster id="">
    
      <host id="www.foo.com" root-directory="/var/www/foo.com">
        <host-alias-regexp>.*foo.com</host-alias-regexp>
    
        <web-app id=""/>
      </host>
    
    </cluster>
    </resin>
    

    <host-default>

    child of cluster

    <host-default> configures defaults for a virtual host.

    The host-default can contain any of the host configuration tags. It will be used as defaults for any virtual host.

    <host-deploy>

    child of cluster

    <host-deploy> configures an automatic deployment directory for virtual host.

    <host-deploy> Attributes
    ATTRIBUTEDESCRIPTIONDEFAULT
    archive-directorypath to the archive directorypath
    pathpath to the deploy directoryrequired
    expand-cleanup-filesetan ant-style fileset defining which directories to cleanup when an archive is redeployed
    expand-directorypath to the expansion directorypath
    host-defaultdefaults for the expanded host
    host-namethe default hostname, based on the directory${name}
    <host-deploy> schema
    element host-deploy {
      archive-directory?
      & expand-cleanup-fileset?
      & expand-directory?
      & host-default?
      & host-name?
      & path?
    }
    

    The following example configures /var/www/hosts as a host deployment directory. Each virtual host will have a webapps directory for .war deployment. So the directory /var/www/hosts/www.foo.com/webapps/bar/test.jsp would serve the URL http://www.foo.com/bar/test.jsp.

    <host-deploy>
    <resin xmlns="http://caucho.com/ns/resin">
      <cluster id="app-tier">
        <root-directory>/var/www</root-directory>
    
        <host-deploy path="hosts">
          <host-default>
            <resin:import path="host.xml" optional="true"/>
    
            <web-app-deploy path="webapps"/>
          </host-default>
        </host-deploy>
      </cluster>
    </resin>
    

    <host-name>

    <host-name> defines the canonical name for a virtual host. The <host-name> will be used in Resin's logging, management, and is available in the host's variables.

    <host-host> schema
    element host-name {
      string
    }
    

    Resources

    All Resource tags are available to the <host>, for example, resources like <database> or <authenticator>. Resources defined at the host level are available for all web-apps in the host.

    Example: shared database in host
    <resin xmlns="http://caucho.com/ns/resin">
      <cluster id="app-tier">
         <server id="a" .../>
    
         <host id="www.foo.com">
            <database jndi-name="jdbc/test">
                <driver type="org.postgresql.Driver">
                    <url>jdbc:postgresql://localhost/test</url>
                    <user>caucho</user>
                </driver>
            </database>
    
            <web-app-default path="webapps"/>
        </host>
      </cluster>
    </resin>
    

    <rewrite-dispatch>

    <rewrite-dispatch> defines a set of rewriting rules for dispatching and forwarding URLs. Applications can use these rules to redirect old URLs to their new replacements.

    See rewrite-dispatch for more details.

    rewrite-dispatch
    <resin xmlns="http://caucho.com/ns/resin">
      <cluster id="app-tier">
    
        <host host-name="www.foo.com">
          <rewrite-dispatch>
            <redirect regexp="^/foo" target="/index.php?foo="/>
          </rewrite-dispatch>
        </host>
    
      </cluster>
    </resin>
    

    <root-directory>

    <root-directory> configures the virtual host's filesystem root.

    Because the virtual host's root will typically contain non-public files like log files, all web-apps should have a path below the host.

    <root-directory> schema
    element root-directory {
      string
    }
    

    <secure-host-name>

    <secure-host-name> sets a host-name or URL to be used for secure redirection. For some security configurations, Resin needs to redirect from an insecure site to a secure one. The <secure-host-name> configures the host to redirect to.

    See Resin security.

    <secure-host-name> schema
    element secure-host-name {
      string
    }
    

    <web-app>

    child of host,web-app

    <web-app> configures a web application.

    <web-app> Attributes
    ATTRIBUTEDESCRIPTIONDEFAULT
    idThe url prefix selecting this application.n/a
    url-regexpA regexp to select this application.n/a
    document-directoryThe document directory for the application, corresponding to a url of /id/. A relative path is relative to the root-directory of the containing host. Can use regexp replacement variables.A relative path constricted with the id or the regexp match
    startup-mode'automatic', 'lazy', or 'manual', see startup-modeautomatic
    redeploy-mode'automatic' or 'manual', see redeploy-modeautomatic

    When specified by id, the application will be initialized on server start. When specified by url-regexp, the application will be initialized at the first request. This means that load-on-startup servlets may start later than expected for url-regexp applications.

    The following example creates a web-app for /apache using the Apache htdocs directory to serve pages.

    Example: custom web-app root
    <resin xmlns="http://caucho.com/ns/resin">
    <cluster id="app-tier">
    
    <host id=''>
      <web-app id='/apache' root-directory='/usr/local/apache/htdocs'>
    
      ...
    
    </host>
    
    </cluster>
    </resin>
    

    The following example sets the root web-app to the IIS root directory.

    Example: IIS root directory
    <resin xmlns="http://caucho.com/ns/resin">
    <cluster id="app-tier">
    <host id=''>
    
      <web-app id='/' root-directory='C:/inetpub/wwwroot'>
    
    </host>
    </cluster>
    </resin>
    

    When the web-app is specified with a url-regexp, root-directory can use replacement variables ($2).

    In the following, each user gets his or her own independent application using ~user.

    Example: web-app root based on regexps
    <resin xmlns="http://caucho.com/ns/resin">
    <cluster id="app-tier">
    
      <host id=''>
    
        <web-app url-regexp='/~([^/]*)'
                 root-directory='/home/$1/public_html'>
    
        ...
    
        </web-app>
    
    </host>
    
    </cluster>
    </resin>
    

    <web-app-default>

    <web-app-default> configures common values for all web applications.

    <web-app-deploy>

    child of host,web-app

    Specifies war expansion.

    web-app-deploy can be used in web-apps to define a subdirectory for war expansion. The tutorials in the documentation use web-app-deploy to allow servlet/tutorial/helloworld to be an independent war file.

    <web-app-deploy> Attributes
    ATTRIBUTEDESCRIPTIONDEFAULT
    archive-directorydirectory containing the .war filesvalue of path
    expand-cleanup-filesetdefines the files which should be automatically deleted when an updated .war expandsall files
    expand-directorydirectory where wars should be expandedvalue of path
    expand-prefixprefix string to use when creating the expansion directory, e.g. _war_
    expand-suffixprefix string to use when creating the expansion directory, e.g. .war
    pathThe path to the webapps directoryrequired
    redeploy-check-intervalHow often to check the .war files for a redeploy60s
    redeploy-mode"automatic" or "manual"automatic
    require-fileadditional files to use for dependency checking for auto restart
    startup-mode"automatic", "lazy" or "manual"automatic
    url-prefixurl-prefix added to all expanded webapps""
    versioningif true, use the web-app's numeric suffix as a versionfalse
    web-app-defaultdefaults to be applied to expaned web-apps
    web-appoverriding configuration for specific web-apps
    <web-app-deploy> schema
    element web-app-deploy {
      archive-directory?
      & expand-cleanup-fileset?
      & expand-directory?
      & expand-prefix?
      & expand-suffix?
      & path?
      & redeploy-check-interval?
      & redeploy-mode?
      & require-file*
      & startup-mode?
      & url-prefix?
      & versioning?
      & web-app-default*
      & web-app*
    }
    

    Overriding web-app-deploy configuration

    The web-app-deploy can override configuration for an expanded war with a matching <web-app> inside the <web-app-deploy>. The <document-directory> is used to match web-apps.

    Example: resin.xml overriding web.xml
    <resin xmlns="http://caucho.com/ns/resin">
    <cluster id="">
    <host id="">
    
    <web-app-deploy path="webapps">
      <web-app context-path="/wiki"
                  document-directory="wiki">
        <context-param database="jdbc/wiki">
      </web-app>
    </web-app-deploy>
    
    </host>
    </cluster>
    </resin>
    

    versioning

    The versioning attribute of the <web-app-deploy> tag improves web-app version updates by enabling a graceful update of sessions. The web-apps are named with numeric suffixes, e.g. foo-10, foo-11, etc, and can be browsed as /foo. When a new version of the web-app is deployed, Resin continues to send current session requests to the previous web-app. New sessions go to the new web-app version. So users will not be aware of the application upgrade.


    Copyright © 1998-2011 Caucho Technology, Inc. All rights reserved.
    Resin ® is a registered trademark, and Quercustm, Ambertm, and Hessiantm are trademarks of Caucho Technology.