Virtual Hosts

From Resin 3.0

Jump to: navigation, search

<document>

 <header>
   <product>resin</product>
   <title>Virtual Hosting</title>
   <description>

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.

   </description>
 </header>
 <body>
   <localtoc/>

<s1 title="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 <a href="../doc/quercus.xtp">Quercus</a> for security and performance.

The virtual host will contain one or more <a href="../reference/webapp-tags.xtp">web-apps</a> 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 title="Example: HTTP request headers"> C: GET /test.jsp HTTP/1.1 C: Host: www.gryffindor.com C: </example>

  1. host name
  2. host aliases
  3. optional host.xml
  4. root directory
  5. web-applications
  6. configuration environment
  7. logging

</s1>

<s1 title="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 <a href="../reference/host-tags.xtp#host-alias"><host-alias></a> 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 title="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

</example>

<s2 title="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 <a href="../reference/host-tags.xtp#host-name"><host-name></a> tag and aliases are configured by <a href="../reference/host-tags.xtp#host-alias"><host-alias></a>. 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 title="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> </example>

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.

</s2>

<s2 title="host-deploy configuration">

The <a href="../reference/host-tags.xtp#host-deploy"><host-deploy></a> 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 <a href="../reference/host-tags.xtp#host-default"><host-default></a> 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 <a href="clustering.xtp">cluster</a> consists of a single server. It includes a <a href="../reference/cluster-tags.xtp#development-mode-error-page"><development-mode-error-page/></a> 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 title="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> </example>

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.

<example> ${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 </example>

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:

<example> ${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 </example>

More information is available in the configuration documentation for <<a href="../reference/host-tags.xtp#host-deploy">host-deploy</a>> and <<a href="../reference/host-tags.xtp#host-default">host-default</a>>.

</s2>

</s1>

<s1 title="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 <a href="../doc/quercus.xtp">Quercus</a> 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 <a href="../doc/resin.xtp#host">host</a> block. At the very least, each host will define the id specifying the host name and a root web-app. A <a config-tag="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 <a href="../reference/webapp-tags.xtp"><web-app></a> 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 <a href="../doc/quercus.xtp">Quercus</a> for security and performance.

<example title="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> </example>

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.

</s1>

<s1 title="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 <a href="watchdog.xtp">watchdog</a> 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.

<figure src="config-jvmpervirtualhost.png" width="481" height="145"/>

<s2 title="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 <a href="rewrite.xtp#load-balance"><resin:LoadBalance></a> 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 title="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> </example>

Each back-end server is started separately:

<example title="Example: starting backend servers"> unix> java -jar lib/resin.jar -server gryffindor start unix> java -jar lib/resin.jar -server slytherin start </example>

<example title="Example: stopping backend servers"> unix> java -jar lib/resin.jar -server gryffindor stop unix> java -jar lib/resin.jar -server slytherin stop </example> </s2>

<s2 title="Resin web-tier load balancer">

The host-specific back-end servers are ready to receive requests on their srun 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.

<figure src="config-jvmpervirtualhost-resin.png" width="481" height="145"/>

The Resin web server is configured using <a href="rewrite.xtp">rewrite</a> with a <a href="rewrite.xtp#load-balance"><resin:LoadBalance</a> 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 title="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> </example>

<s3 title="Starting the servers on Unix">

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

<example title="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 </example>

</s3>

<s3 title="Starting the servers on Windows">

With Windows, each JVM is installed as a service.

<example title="Example: installing as win32 service"> win> resin.exe -install-as "Resin" \

           -server resin -conf conf/resin.xml

win> resin.exe -install-as "Resin www.gryffindor.com" \

           -server gryffindor -conf conf/gryffindor.xml

win> resin.exe -install-as "Resin www.slytherin.com" \

           -server slytherin -conf conf/slytherin.xml

</example>

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.

</s3>

</s2>

</s1>

<s1 title="Configuration tasks">

<s2 title="host naming">

The virtual host name can be configured by an explicit <a href="../reference/host-tags.xtp#host-name"><host-name></a>, a <a href="../reference/host-tags.xtp#host-alias"><host-alias></a>, a <a href="../reference/host-tags.xtp#host-alias-regexp"><host-alias-regexp></a>, by the <a href="../reference/host-tags.xtp#host"><host></a> tag or implicitly by the <a href="../reference/host-tags.xtp#host-deploy"><host-deploy></a>. 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.

</s2>

<s2 title="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 <a href="candi.xtp">beans and services</a>. 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 <a href="../reference/env-tags.xtp#import"><resin:import></a> 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.

</s2>

<s2 title="web-applications">

Hosts must define <a href="../reference/webapp-tags.xtp">web-apps</a> 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 <a href="../reference/webapp-tags.xtp#web-app"><web-app></a> and dynamic <a href="../reference/webapp-tags.xtp#web-app-deploy">web-app-deploy</a> 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.

</s2>

</s1>


<s1 title="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.

<example> <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> </example>

</s1>

<s1 title="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. <a href="http://devedge.netscape.com/viewsource/2003/idn/">Mozilla 1.4</a> supports the encoding.

</s1>

<s1 title="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.

<s2 title="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 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.

<example title="httpd.conf"> LoadModule caucho_module /usr/local/apache/libexec/mod_caucho.so

ResinConfigServer localhost 6802

<VirtualHost 127.0.0.1>

 ServerName gryffindor.caucho.com

</VirtualHost>

<VirtualHost 192.168.0.1>

 ServerName slytherin.caucho.com

</VirtualHost> </example>

<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.</note> </s2>


<s2 title="Apache front-end">

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

<figure src="config-jvmpervirtualhost-apache.png" width="481" height="145"/>

<example title="httpd.conf"> <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> </example>

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.

</s2>

<s2 title="IIS">

Configuration and installation for IIS virtual sites is discussed in the <a href="../install/install-3rd-party.xtp">IIS installation</a> section.

</s2> </s1>

<s1 title="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:

<example title="/etc/hosts"> 127.0.0.1 localhost

127.0.0.1 www.gryffindor.com 127.0.0.1 www.slytherin.com </example>

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

<example title="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 </example>

</s1>


 </body>

</document>

<document> <header>

 <title><host>: Virtual Host configuration</title>
 <version>Resin 3.1</version>
 <description>

Describes the virtual host configuration tags.

 </description>

</header> <body>

<localtoc/>

<s1 title="See Also">

  • See the <a href="index-tags.xtp">index</a> for a list of all the tags.
  • See <a href="webapp-tags.xtp">Web Application</a> configuration for web.xml (Servlet) configuration.
  • See <a href="env-tags.xtp">Resource</a> configuration for resources: classloader, databases, JMS, EJB, and IoC beans.
  • See <a href="config-log.xtp">Log</a> configuration for access log configuration, java.util.logging, and stdout/stderr logging.

</s1>

<defun title="<access-log>" version="Resin 2.1"> <parents>cluster, host, web-app</parents>

<access-log> configures the access log file.

As a child of <a config-tag="web-app"/>, overrides the definition in the <a config-tag="host"/> that the web-app is deployed in. As a child of <a config-tag="host"/>, overrides the definition in the <a config-tag="server"/> that the host is in.

<deftable title="<access-log> Attributes"> <tr>

 <th>Attribute</th>
 <th>Description</th>
 <th>Default</th>

</tr> <tr>

 <td>archive-format</td>
 <td>the format for the archive filename when a rollover occurs,
       see <a href="#rollover">Rollovers</a>.
 </td>
 <td>see below</td>

</tr> <tr>

 <td>format</td>
 <td>Access log format.</td>
 <td>see below</td>

</tr> <tr>

 <td>hostname-dns-lookup</td>
 <td>log the dns name instead of the IP address (has a performance hit).</td>
 <td>false</td>

</tr> <tr>

 <td>path</td>
 <td>Output path for the log entries,

see <a href="config-log.xtp#path">"Log Paths"</a>.</td>

 <td>required</td>

</tr> <tr>

 <td>rollover-period</td>
 <td>how often to rollover the log.  Specify in days (15D), weeks (2W), 
       months (1M), or hours (1h). See <a href="#rollover">Rollovers</a>. 
 </td>
 <td>none</td>

</tr> <tr>

 <td>rollover-size</td>
 <td>maximum size of the file before a rollover occurs, in bytes (50000), 
       kb (128kb), or megabytes (10mb).  
       See <a href="#rollover">Rollovers</a>.
 </td>
 <td>1mb</td>

</tr> <tr>

 <td>resin:type</td>
 <td>a class extending <a href="javadoc|com.caucho.server.log.AccessLog|"/>
       for custom logging
 </td>
 <td>com.caucho.server.log.AccessLog</td>

</tr> <tr>

 <td>init</td>
 <td>Resin-IoC initialization for the custom class</td>
 <td>n/a</td>

</tr> </deftable>

<def title="<access-log> schema"> element access-log {

 auto-flush?
 & archive-format?
 & auto-flush-time?
 & exclude?
 & format?
 & path?
 & rollover-count?
 & rollover-period?
 & rollover-size?
 & init?

} </def>

The default archive format is

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

The access log formatting variables follow the Apache variables:

<deftable title="format patterns"> <tr>

 <th>Pattern</th>
 <th>Description</th>

</tr> <tr><td>%b</td>

   <td>result content length</td></tr>

<tr><td>%D</td>

   <td>time taken to complete the request in microseconds (since 3.0.16)</td></tr>

<tr><td>%h</td>

   <td>remote IP addr</td></tr>

<tr><td>%{xxx}i</td>

   <td>request header xxx</td></tr>

<tr><td>%{xxx}o</td>

   <td>response header xxx</td></tr>

<tr><td>%{xxx}c</td>

   <td>cookie value xxx</td></tr>

<tr><td>%n</td>

   <td>request attribute</td></tr>

<tr><td>%r</td>

   <td>request URL</td></tr>

<tr><td>%s</td>

   <td>status code</td></tr>

<tr><td>%{xxx}t</td>

   <td>request date with optional time format string.</td></tr>

<tr><td>%T</td>

   <td>time taken to complete the request in seconds</td></tr>

<tr><td>%u</td>

   <td>remote user</td></tr>

<tr><td>%U</td>

   <td>request URI</td></tr>

</deftable>

The default format is:

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

resin:type allows for custom logging. Applications can extend a custom class from <a href="javadoc|com.caucho.http.log.AccessLog|"/>. <a href="resin-ioc.xtp">Resin-IoC initialization</a> can be used to set bean parameters in the custom class.

<example title="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>

<example title="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> </example>

</defun>

<defun title="<ear-deploy>"> <parents>host, web-app</parents>

Specifies ear expansion.

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

<deftable title="<ear-deploy> Attributes"> <tr>

 <th>Attribute</th>
 <th>Description</th>
 <th>Default</th>

</tr> <tr>

 <td>archive-path</td>
 <td>The path to the directory containing ear files</td>
 <td>path</td>

</tr> <tr>

 <td>ear-default</td>
 <td>resin.xml default configuration for all ear files, e.g. configuring

database, JMS or EJB defaults.</td>

 <td></td>

</tr> <tr>

 <td>expand-cleanup-fileset</td>
 <td>Specifies the files which should be automatically deleted when a

new .ear version is deployed.</td>

 <td></td>

</tr> <tr>

 <td>expand-directory</td>
 <td>directory where ears should be expanded</td>
 <td>value of path</td>

</tr> <tr>

 <td>expand-prefix</td>
 <td>automatic prefix of the expanded directory</td>
 <td>_ear_</td>

</tr> <tr>

 <td>expand-suffix</td>
 <td>automatic suffix of the expanded directory</td>
 <td></td>

</tr> <tr>

 <td>lazy-init</td>
 <td>if true, the ear file is only started on first access</td>
 <td>false</td>

</tr> <tr>

 <td>path</td>
 <td>The path to the deploy directory</td>
 <td>required</td>

</tr> <tr>

 <td>redeploy-mode</td>
 <td>"automatic" or "manual".  If automatic, detects new .ear files

automatically and deploys them.</td>

 <td>automatic</td>

</tr> <tr>

 <td>url-prefix</td>
 <td>optional URL prefix to group deployed .ear files</td>
 <td></td>

</tr> </deftable>

<def title="<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?

} </def>

</defun>

<defun title="<error-page>" version="Resin 3.1"> <parents>cluster, host, webapp</parents>

<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 <a href="webapp.xtp#error-page">webapp: error-page</a>.

</defun>

<defun title="<host>" version="Resin 3.0"> <parents>cluster</parents>

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

<deftable title="<host> Attributes"> <tr>

 <th>Attribute</th>
 <th>Description</th>
 <th>Default</th>

</tr> <tr><td>id</td>

   <td>primary host name</td>
   <td>none</td></tr>

<tr><td>regexp</td>

   <td>Regular expression based host matching</td>
   <td>none</td></tr>

<tr><td>host-name</td>

   <td>Canonical host name</td>
   <td>none</td></tr>

<tr><td>host-alias</td>

   <td>Aliases matching the same host</td>
   <td>none</td></tr>

<tr><td>secure-host-name</td>

   <td>Host to use for a redirect to SSL</td>
   <td>none</td></tr>

<tr><td>root-directory</td>

   <td>Root directory for host files</td>
   <td>parent directory</td></tr>

<tr><td>startup-mode</td>

   <td>'automatic', 'lazy', or 'manual', see <a href="resin-tags.xtp#startup-mode">Startup and Redeploy Mode</a></td>
   <td>automatic</td></tr>

</deftable>

<example title="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>

<example title="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> </example>

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

</defun>

<defun title="<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.

<def title="<host-alias> schema"> element host-alias {

 string

} </def>

<example title="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> </example>

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 title="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> </example>

</defun>

<defun title="<host-alias-regexp>">

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

<def title="<host-alias-regexp> schema"> element host-alias-regexp {

 string

} </def>

<example title="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> </example>

</defun>

<defun title="<host-default>" version="Resin 3.0"> <parents>cluster</parents>

<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.

</defun>

<defun title="<host-deploy>" version="Resin 3.0.4"> <parents>cluster</parents>

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

<deftable title="<host-deploy> Attributes"> <tr>

 <th>Attribute</th>
 <th>Description</th>
 <th>Default</th>

</tr> <tr>

 <td>archive-directory</td>
 <td>path to the archive directory</td>
 <td>path</td>

</tr> <tr>

 <td>path</td>
 <td>path to the deploy directory</td>
 <td>required</td>

</tr> <tr>

 <td>expand-cleanup-fileset</td>
 <td>an ant-style fileset defining which directories to cleanup when

an archive is redeployed</td>

 <td></td>

</tr> <tr>

 <td>expand-directory</td>
 <td>path to the expansion directory</td>
 <td>path</td>

</tr> <tr>

 <td>host-default</td>
 <td>defaults for the expanded host</td>
 <td></td>

</tr> <tr>

 <td>host-name</td>
 <td>the default hostname, based on the directory</td>
 <td>${name}</td>

</tr> </deftable>

<def title="<host-deploy> schema"> element host-deploy {

 archive-directory?
 & expand-cleanup-fileset?
 & expand-directory?
 & host-default?
 & host-name?
 & path?

} </def>

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.

<example title="<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> </example>

</defun>

<defun title="<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.

<def title="<host-host> schema"> element host-name {

 string

} </def>

</defun>

<defun title="<redeploy-mode>">

<redeploy-mode> configures the virtual-host's behavior when it detects changes in configuration files or classes. The <dependency-check-interval> controls how often the virtual host will check for updates.

<deftable title="startup-mode values"> <tr>

 <th>Mode</th>
 <th>Description</th>

</tr> <tr>

 <td>automatic</td>
 <td>automatically restart when detecting changes</td>

</tr> <tr>

 <td>manual</td>
 <td>only restart only on a JMX administration request</td>

</tr> </deftable>

<def title="<restart-mode> schema"> element startup-mode {

 string

} </def>

</defun>

<defun title="Resources" version="Resin 3.1"> <parents>resin, cluster, host, web-app</parents>

All <a href="env-tags.xtp">Resource tags</a> 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 title="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> </example>

</defun>

<defun title="<rewrite-dispatch>" version="Resin 3.1"> <parents>cluster, host, web-app</parents>

<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 <a href="rewrite-tags.xtp">rewrite-dispatch</a> for more details.

<example title="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> </example>

</defun>

<defun title="<root-directory>" version="Resin 3.1">

<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.

<def title="<root-directory> schema"> element root-directory {

 string

} </def>

</defun>

<defun title="<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 <a href="resin-security.xtp">Resin security</a>.

<def title="<secure-host-name> schema"> element secure-host-name {

 string

} </def>

</defun>

<defun title="<startup-mode>">

<startup-mode> configures the virtual-host's behavior on Resin startup, either "automatic", "lazy" or "manual".

<deftable title="startup-mode values"> <tr>

 <th>Mode</th>
 <th>Description</th>

</tr> <tr>

 <td>automatic</td>
 <td>automatically start when Resin starts</td>

</tr> <tr>

 <td>lazy</td>
 <td>start only when the first request is received</td>

</tr> <tr>

 <td>manual</td>
 <td>start only when JMX administration requests a start</td>

</tr> </deftable>

<def title="<startup-mode> schema"> element startup-mode {

 string

} </def>

</defun>

<defun title="<web-app>"> <parents>host, web-app</parents>

<web-app> configures a web application.

<deftable title="<web-app> Attributes"> <tr>

 <th>Attribute</th>
 <th>Description</th>
 <th>Default</th>

</tr> <tr>

 <td>id</td>
 <td>The url prefix selecting this application.</td>
 <td>n/a</td>

</tr> <tr>

 <td>url-regexp</td>
 <td>A regexp to select this application.</td>
 <td>n/a</td>

</tr> <tr>

 <td>document-directory</td>
 <td>The document directory for

the application, corresponding to a url of /id/. A relative path is relative to the <a config-tag="root-directory"/> of the containing <a config-tag="host"/>. Can use regexp replacement variables.</td><td>A relative path constricted with the id or the regexp match </td> </tr> <tr>

 <td>startup-mode</td>
 <td>'automatic', 'lazy', or 'manual', see <a href="resin.xtp#startup-mode">Startup and Redeploy Mode</a></td>
 <td>automatic</td>

</tr> <tr>

 <td>redeploy-mode</td>
 <td>'automatic' or 'manual', see <a href="resin.xtp#startup-mode">Startup and Redeploy Mode</a></td>
 <td>automatic</td>

</tr> </deftable>

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 title="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> </example>

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

<example title="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> </example>

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 title="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> </example>

</defun>

<defun title="<web-app-default>"> <parents>cluster, host, web-app</parents>

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

</defun>

<defun title="<web-app-deploy>" type="defun"> <parents>host, web-app</parents>

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.

<deftable title="<web-app-deploy> Attributes"> <tr>

 <th>Attribute</th>
 <th>Description</th>
 <th>Default</th>

</tr> <tr>

 <td>archive-directory</td>
 <td>directory containing the .war files</td>
 <td>value of path</td>

</tr> <tr>

 <td>expand-cleanup-fileset</td>
 <td>defines the files which should be automatically deleted

when an updated .war expands</td>

 <td>all files</td>

</tr> <tr>

 <td>expand-directory</td>
 <td>directory where wars should be expanded</td>
 <td>value of path</td>

</tr> <tr>

 <td>expand-prefix</td>
 <td>prefix string to use when creating the expansion directory, e.g. _war_</td>
 <td></td>

</tr> <tr>

 <td>expand-suffix</td>
 <td>prefix string to use when creating the expansion directory, e.g. .war</td>
 <td></td>

</tr> <tr>

 <td>path</td>
 <td>The path to the webapps directory</td>
 <td>required</td>

</tr> <tr>

 <td>redeploy-check-interval</td>
 <td>How often to check the .war files for a redeploy</td>
 <td>60s</td>

</tr> <tr>

 <td>redeploy-mode</td>
 <td>"automatic" or "manual"</td>
 <td>automatic</td>

</tr> <tr>

 <td>require-file</td>
 <td>additional files to use for dependency checking for auto restart</td>
 <td></td>

</tr> <tr>

 <td>startup-mode</td>
 <td>"automatic", "lazy" or "manual"</td>
 <td>automatic</td>

</tr> <tr>

 <td>url-prefix</td>
 <td>url-prefix added to all expanded webapps</td>
 <td>""</td>

</tr> <tr>

 <td>versioning</td>
 <td>if true, use the web-app's numeric suffix as a version</td>
 <td>false</td>

</tr> <tr>

 <td>web-app-default</td>
 <td>defaults to be applied to expaned web-apps</td>
 <td></td>

</tr> <tr>

 <td>web-app</td>
 <td>overriding configuration for specific web-apps</td>
 <td></td>

</tr> </deftable>

<def title="<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*

} </def>

<s2 title="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 title="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> </example>

</s2>

<s2 title="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.

</s2>

</defun>

</body> </document>

Personal tools