⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 virtual-host.xtp

📁 RESIN 3.2 最新源码
💻 XTP
📖 第 1 页 / 共 2 页
字号:
<document>  <header>    <product>resin</product>    <title>Virtual Hosting</title>    <description><p>A Resin server can serve many virtual hosts, each withits own servlets and documents.  The configuration is flexible,allowing dynamic host deployment in a <code>hosts</code> directoryor using explicit &lt;host> tags for additional control and security,and compatibility with existing Apache sites, enabling easy upgradesand evaluation for PHP servers to Quercus.</p>    </description>  </header>  <body>    <localtoc/><s1 title="Overview"><p>Virtual hosts are multiple internet domains served by the sameResin server.  Because one JVM handles all the domains, its more memoryand processing efficient, as well as sharing IP addresses.  With Resin,adding virtual hosts can as easy as creating a directorylike <code>/var/www/hosts/foo.com</code> and setting up the DNS name.Explicit virtual host is also possible to match existing layouts, likematching a <code>/var/www/htdocs</code> configuration when migratinga PHP mediawiki or wordpress site to use <a href="quercus.xtp">Quercus</a>for security and performance.</p><p>The virtual host will contain one ormore <a href="webapp-tags.xtp">web-apps</a> to serve the host's contents.Simple sites will use a fixed root webapp, like the Apache-style<code>/var/www/htdocs</code>.  More complicated sites can use a<code>webapps</code>-style directory.</p><p>Each virtual host belongs to aResin <a href="resin-clustering.xtp">&lt;cluster></a>, even if thecluster has only a single server.</p><p>For example, a Resin server might manage both the<code>www.gryffindor.com</code> and <code>www.slytherin.com</code> 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 areregistered with the standard domain name service registry as having the IPaddress <code>192.168.0.13</code>.  When a user types in the url<code>http://www.gryffindor.com/hello.jsp</code> in their browser,the browser will send the HTTP request to the IP address<code>192.168.0.13</code> and send an additional HTTP header for thegryffindor host, "Host: www.gryffindor.com".  When Resin receives the requestit will grab the host header, and dispatch the request to the configuredvirtual host.</p><example title="Example: HTTP request headers">C: GET /test.jsp HTTP/1.1C: Host: www.gryffindor.comC:</example><ol><li>host name</li><li>host aliases</li><li>optional host.xml</li><li>root directory</li><li>web-applications</li><li>configuration environment</li><li>logging</li></ol></s1><s1 title="Dynamic virtual hosts"><p>Resin can deploy virtual hosts automatically by scanning a hostdeployment directory for virtual host content.  Each sub-directory inthe <code>hosts</code> directory will cause Resin to create a newvirtual host.  To customize the configuration, you canadd a <code>host.xml</code> in the host's root directory for shareddatabases, beans or security, or to add<a href="host-tags.xtp#host-alias">&lt;host-alias></a> names.</p><p>You can add hosts dynamically to a running server just by creatinga new host directory.  Resin periodically scans the <code>hosts</code>directory looking for directory changes.  When it detects a new host directory,it will automatically start serving files from the new virtual hosts.</p><p>If you add a <code>default</code> directory in the <code>hosts</code>,Resin will use it to serve all unknown virtual hosts.  The default host ishandy for simple servers with only a single virtual host and for siteswhere the virtual host is handled in software, like Drupal. If the<code>default</code> directory is missing, Resin willreturn <code>404 Not Found</code> for any unknown virtual hosts.</p><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"><p>Often, the same virtual host will respond to multiple names, like<code>www.slytherin.com</code> and <code>slytherin.com</code>.  Onename is the primary name and the others are aliases.  In Resin, theprimary name is configured by the <a href="host-tags.xtp#host-name">&lt;host-name></a> tag and aliases are configuredby <a href="host-tags.xtp#host-alias">&lt;host-alias></a>.  In a dynamichost configuration, the directory name is used as the <code>host-name</code>by default, and aliases are declared in the <code>host.xml</code>.</p><example title="Example: www.slytherin.com/host.xml">&lt;host xmlns="http://caucho.com/ns/resin">  &lt;host-name>www.slytherin.com&lt;/host-name>  &lt;host-alias>slytherin.com&lt;/host-alias>  &lt;host-alias>quidditch.slytherin.com&lt;/host-alias>&lt;/host></example><p>Since the <code>host.xml</code> is shared for all web-applications inthe host, you can also use it to configure shared resources like securitylogins, shared databases, and shared resources.</p></s2><s2 title="host-deploy configuration"><p>The <a href="host-tags.xtp#host-deploy">&lt;host-deploy></a> tag configuresthe dynamic virtual hosting specifying the directory where Resin shouldscan for virtual hosts.  Because Resin does not automatically add defaultconfiguration, you will need to also add configuration for the<code>host.xml</code>, <code>app-default.xml</code> and<code>web-app-deploy</code>.  Although it's a bit more verbose, theno-default rule makes Resin more secure and debuggable.  If an item likea &lt;web-app> is missing, Resin will return <code>404 Not Found</code> forsecurity.  Because all configuration is explicit, it's ultimately traceableto the <code>resin.xml</code> which makes debugging more reliable.</p><p>Shared host configuration goes in the<a href="host-tags.xtp#host-default">&lt;host-default></a> tag.  In thiscase, we've added an optional <code>host.xml</code> for configuration,an access log in <code>log/access.log</code> and a standard<code>webapps</code> directory.  The standard servlets and file handlingcome from the <code>app-default.xml</code> file.  If you omit either theapp-default.xml or the webapps, you will see <code>404 Not Found</code> forany requests.</p><p>The example below is a complete, working <code>resin.xml</code> listeningto HTTP at port 8080.  The <a href="resin-clustering.xtp">cluster</a>consists of a single server.  It includes a <a href="cluster-tags.xtp#development-mode-error-page">&lt;development-mode-error-page/></a> to help debuggingthe configuration.  Many sites will omit the error-page tohide configuration details in case an error occurs on a live site.</p><example title="Example: /etc/resin/resin.xml host-deploy configuration">&lt;resin xmlns="http://caucho.com/ns/resin"          xmlns:resin="http://caucho.com/ns/resin/core"&gt;&lt;cluster id="app-tier">  &lt;server id="app-a" address="192.168.1.13" port="6800">    &lt;http port="8080"/>  &lt;/server>  &lt;development-mode-error-page/>  &lt;resin:import path="${__FILE__}/../app-default.xml"/>    &lt;host-default&gt;    &lt;resin:import path="host.xml" optional="true"/>    &lt;access-log path="log/access.log"/>	    &lt;web-app-deploy path="webapps"/&gt;  &lt;/host-default&gt;  <b>&lt;host-deploy path="hosts"&gt;  &lt;/host-deploy&gt;</b>  &lt;/cluster&gt;&lt;/resin&gt;</example><p>Any directory created in <code>${resin.root}/hosts</code> will nowbecome a virtualhost. You can also place a .jar file in <code>${resin.root}/hosts</code>, it is expanded tobecome a virtual host.</p><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><p>Jar libraries and class files that are shared amongst all webapps in the hostcan be placed in <code>lib</code> and <code>classes</code> subdirectories of the host:</p><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><p>More information is available in the configuration documentationfor &lt;<a href="host-tags.xtp#host-deploy">host-deploy</a>&gt;and &lt;<a href="host-tags.xtp#host-default">host-default</a>&gt;.</p></s2></s1><s1 title="Explicit Virtual Hosting"><p>In a more structured site, you can take complete control of thevirtual host configuration and configure each virtual host explicitly.Existing sites wanting to upgrade to Resin or sites with extra security needsmay prefer to configure each &lt;host>  in the resin.xml. Forexample, a PHP Drupal site evaluating <a href="quercus.xtp">Quercus</a> toimprove performance and security might use the explicit &lt;host> topoint to the existing <code>/var/www/htdocs</code> directory.</p><p>In the explicit configuration, each virtual host has itsown <a href="resin.xtp#host">host</a> block.  At the very least, each hostwill define the <var>id</var> specifying the host name and a root web-app.A <a config-tag="root-directory"/> is often used to provide a host specificroot for logfiles.</p><p>As with the dynamic hosting, servlets and web-apps must be configuredeither in a &lt;host-default> or explicitly.  If they are missing, Resinwill return a <code>404 Not Found</code> for security.  The host id=""is the default host and will serve any request that doesn't match otherhosts.  If you don't have a default host, Resin will return a<code>404 Not Found</code> for any unknown host.</p><p>The following sample configuration defines an explicit virtual hostswww.slytherin.com and a default host, each with its ownroot directory, access-log and a single explicit<a href="webapp-tags.xtp">&lt;web-app></a> in the <code>htdocs</code>directory.  The default virtual host is configured just like a typicalApache configuration, so it can be used to upgrade an Apache/PHP siteto use <a href="quercus.xtp">Quercus</a> for security and performance.</p><example title="Example: /etc/resin/resin.xml">&lt;resin xmlns="http://caucho.com/ns/resin">&lt;cluster id="app-tier">  &lt;server id="app-a" address="192.168.1.10" port="6800"&gt;    &lt;http port="8080"/>  &lt;/server>  &lt;development-mode-error-page/>  &lt;resin:import path="${__FILE__}/../app-default.xml"/>  &lt;host id="">    &lt;root-directory&gt;/var/www&lt;/root-directory&gt;    &lt;access-log path="logs/access.log"/>    &lt;web-app id="" root-directory="htdocs"/>  &lt;/host>  &lt;host id="www.slytherin.com">    &lt;host-alias>slytherin.com&lt;/host-alias>        &lt;root-directory&gt;/var/slytherin&lt;/root-directory&gt;    &lt;access-log path="logs/access.log"/>    &lt;web-app id="" root-directory="htdocs"/>  &lt;/host>&lt;/cluster&gt;&lt;/resin&gt;</example><p>Browsing http://gryffindor.caucho.com/test.php will look for/var/www/htdocs/test.php.</p><p>Browsing http://slytherin.caucho.com/test.php will look for/var/slytherin/htdocs/test.php.</p></s1><s1 title="Server per virtual host"><p>In some ISP setups, it may make sense to assign a server for eachvirtual host.  The isolation of web-apps may not besufficient; each host needs a separate JVM.  In this configuration,each &lt;host> belongs to its own &lt;cluster> and has a dedicated&lt;server>.  Normally, this configuration will operate using load-balancing,so the load-balance server will dispatch requests as appropriate.</p><p>For further security restrictions, seethe <a href="resin-watchdog.xtp">watchdog</a> section.  ISPs can alsouse the watchdog to assign different &lt;user-name> values for eachhost and can even create chroot directories for each JVM.</p><p>A front-end web server receives all requests, and is configured todispatch to back-end Resin server that correspond to the host name.</p><figure src="config-jvmpervirtualhost.png" width="481" height="145"/><s2 title="Back-end JVMs"><p>Each host is placed in its own &lt;cluster> with a dedicated&lt;server>.  Since the server listens to a TCP port for load-balancingand clustering messages, each server on the maching needs a differentserver port.</p><p>In this example, the virtual hosts <code>www.gryffindor.com</code> and<code>www.slytherin.com</code> each get their own server.  The backendclusters have their own virtual host.  The frontend load-balancer dispatchesthe <a href="rewrite-tags.xtp#load-balance">&lt;load-balance></a> tagsto the backend.</p><p>This example is split into two blocks to emphasize the frontend andbackend.  Typically, they will both actually be in the same resin.xmlto ensure consistency.</p><example title="Example: /etc/resin/resin.xml for backend">&lt;resin xmlns="http://caucho.com/ns/resin"          xmlns:resin="http://caucho.com/ns/resin/core">  &lt;cluster-default>    &lt;resin:import path="${resin.home}/conf/app-default.xml"/>        &lt;host-default>      &lt;web-app-deploy path="webapps"/>    &lt;/host-default>  &lt;/cluster-default>  &lt;cluster id="gryffindor&gt;    &lt;server id="gryffindor" host="localhost" port="6800"/&gt;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -