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/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 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"/> </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/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. 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 maching 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"/> </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: unix> java -jar lib/resin.jar -server gryffindor start unix> java -jar lib/resin.jar -server slytherin start unix> java -jar lib/resin.jar -server gryffindor stop unix> java -jar lib/resin.jar -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> 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 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 <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 + ".%Y%m%d" or + ".%Y%m%d.%H" if rollover-period < 1 day. The access log formatting variables follow the Apache variables:
The default format is: "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" com.caucho.http.log.AccessLog. Resin-IoC initialization can be used to set bean parameters in the custom class. allows for custom logging. Applications can extend a custom class from
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? } <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> <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> Specifies ear expansion. ear-deploy can be used in web-apps to define a subdirectory for ear expansion.
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> 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. child of cluster
<host> configures a virtual host. Virtual hosts must be configured explicitly.
<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> <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> 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. element host-alias { string } <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. <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> defines a regular expression for matching URLs for a given virtual host. element host-alias-regexp { string } <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> 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. child of cluster
<host-deploy> configures an automatic deployment directory for virtual host.
element host-deploy { archive-directory? & expand-cleanup-fileset? & expand-directory? & host-default? & host-name? & path? } The following example configures as a host deployment directory. Each virtual host will have a directory for .war deployment. So the directory would serve the URL .<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> 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. element host-name { string } 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. <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> 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. <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> 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. element root-directory { string } <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. element secure-host-name { string } <web-app> configures a web application.
When specified by , the application will be initialized on server start. When specified by , the application will be initialized at the first request. This means that servlets may start later than expected for applications.The following example creates a web-app for /apache using the Apache htdocs directory to serve pages. <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. <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 is specified with a , can use replacement variables ( ).In the following, each user gets his or her own independent application using .<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> configures common values for all web applications. 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.
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 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.
|