Resin Documentationapp server |
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 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 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
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
C: GET /test.jsp HTTP/1.1 C: Host: www.gryffindor.com C:
Resin can deploy virtual hosts automatically by scanning a host
deployment directory for virtual host content. Each sub-directory in
the You can add hosts dynamically to a running server just by creating
a new host directory. Resin periodically scans the If you add a /var/resin/hosts/www.gryffindor.com/ host.xml log/access.log webapps/ROOT/index.jsp webapps/ROOT/WEB-INF/resin-web.xml /var/resin/hosts/www.slytherin.com/ host.xml log/access.log webapps/ROOT/index.php webapps/ROOT/WEB-INF/resin-web.xml /var/resin/hosts/default/ host.xml log/access.log webapps/ROOT/index.php webapps/ROOT/WEB-INF/resin-web.xml host-aliasing for dynamic hostsOften, the same virtual host will respond to multiple names, like
<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-deploy configurationThe <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
Shared host configuration goes in the
<host-default> tag. In this
case, we've added an optional The example below is a complete, working <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" expand-preserve-fileset="WEB-INF/work/**"/> </host-default> <host-deploy path="hosts"> </host-deploy> </cluster> </resin> Any directory created in ${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 ${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>. 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 In the explicit configuration, each virtual host has its own host block. At the very least, each host will define the 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 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 <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/resin</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/resin/htdocs/test.php. Browsing http://slytherin.caucho.com/test.php will look for /var/slytherin/htdocs/test.php. 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 JVMsEach 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 machine needs a different server port. In this example, the virtual hosts 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. <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" expand-preserve-fileset="WEB-INF/work/**"/> </host-default> </cluster-default> <cluster id="gryffindor> <server id="gryffindor" host="localhost" port="6800"/> <host id="www.gryffindor.com"> <root-directory>/var/resin/gryffindor</root-directory> </host> </cluster> <cluster id="slytherin"> <server id="slytherin" host="localhost" port="6801"/> <host id="www.slytherin.com"> <root-directory>/var/resin/slytherin</root-directory> </host> </cluster> <cluster id="web-tier"> <!-- see below --> ... </cluster> </resin> Each back-end server is started separately: unix> bin/resin.sh -server gryffindor start unix> bin/resin.sh -server slytherin start unix> bin/resin.sh -server gryffindor stop unix> bin/resin.sh -server slytherin stop Resin web-tier load balancerThe 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. <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 UnixThe front-end server JVM is started similar to the back-end JVMs: unix> bin/resin.sh -server web -conf conf/resin.xml start ... unix> bin/resin.sh -server web -conf conf/resin.xml stop Starting the servers on WindowsWith 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. host namingThe 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 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 host.xmlThe The web-applicationsHosts must define web-apps in order to
serve files, servlets, or PHP pages. If the host is missing all
webapps, Resin will return 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 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> 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. A common configuration uses virtual hosts with Apache or IIS. As usual, Apache or IIS will pass matching requests to Resin. ApacheThe 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 directive in Apache with the 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 . Without the , Apache will use the "Host:" header in the HTTP request to select which host to serve.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-endThe 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: 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 and to check your configuration. Check that each virtual host is using the server and that you expect.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 127.0.0.1 localhost 127.0.0.1 www.gryffindor.com 127.0.0.1 www.slytherin.com Windows user edit the file 127.0.0.1 localhost 127.0.0.1 www.gryffindor.com 127.0.0.1 www.slytherin.com Overriding web-app-deploy configurationThe 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. <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> versioningThe 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.
|