📄 virtual-host.xtp
字号:
<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><p>Each back-end server is started separately:</p><example title="Example: starting backend servers">unix> java -jar lib/resin.jar -server gryffindor startunix> java -jar lib/resin.jar -server slytherin start</example><example title="Example: stopping backend servers">unix> java -jar lib/resin.jar -server gryffindor stopunix> java -jar lib/resin.jar -server slytherin stop</example></s2><s2 title="Resin web-tier load balancer"><p>The host-specific back-end servers are ready to receive requests on their srunports. A third Resin server can be used as the front-end load-balancer.It receives all requests and dispatches to the back-end servers.</p><figure src="config-jvmpervirtualhost-resin.png" width="481" height="145"/><p>The Resin web server is configured using <a href="rewrite-tags.xtp"><rewrite-dispatch></a> with a <a href="rewrite-tags.xtp#load-balance"><load-balance</a> directive to dispatch to the back-end server. A cluster isdefined for each back-end host, so that the<load-balance> knows how to find them.</p><example title="Example: /etc/resin/resin.xml for front-end web server"><resin xmlns="http://caucho.com/ns/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="/"> <rewrite-dispatch> <load-balance regexp="" cluster="gryffindor"/> <rewrite-dispatch> </web-app> </host> <host id="slytherin.com"> <web-app id="/"> <rewrite-dispatch> <load-balance regexp="" cluster="slytherin"/> <rewrite-dispatch> </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"><p>The front-end server JVM is started similar to the back-end JVMs:</p><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> <!-- unix startup --><s3 title="Starting the servers on Windows"><p>With Windows, each JVM is installed as a service.</p><example title="Example: installing as win32 service">win> resin.exe -install-as "Resin" -server resin -conf conf/resin.xmlwin> resin.exe -install-as "Resin www.gryffindor.com" -server gryffindor -conf conf/gryffindor.xmlwin> resin.exe -install-as "Resin www.slytherin.com"-server slytherin -conf conf/slytherin.xml</example><p>You will either need to reboot the machine or start the service from theControl Panel/Services panel to start the server. On a machine reboot, NT willautomatically start the service.</p><p>There is a bug in many JDKs which cause the JDK to exit when theadministrator logs out. JDK 1.4 and later can avoid that bug if the JDK isstarted with -Xrs.</p></s3> <!-- windows startup --></s2> <!-- resin frontend --></s1> <!-- jvm per virtual host --><s1 title="Configuration tasks"><s2 title="host naming"><p>The virtual host name can be configured byan explicit <a href="host-tags.xtp#host-name"><host-name></a>, a <a href="host-tags.xtp#host-alias"><host-alias></a>,a <a href="host-tags.xtp#host-alias-regexp"><host-alias-regexp></a>,by the <a href="host-tags.xtp#host"><host></a> tag or implicitly by the <a href="host-tags.xtp#host-deploy"><host-deploy></a>.For explicit configuration styles, the host name and aliasconfiguration will generally be in the resin.xml. For dynamic configuration,the host aliases will typically be in an included <code>host.xml</code> insidethe host directory.</p><p>The default host catches all unmatches hosts. Simpler sites willuse the default host for all requests, while security-conscious sitesmay remove the default host entirely. If the default host is not configured,Resin will return a <code>404 Not Found</code>.</p></s2><s2 title="host.xml"><p>The <code>host.xml</code> is an optional file where virtual hosts canput host-common configuration. The <code>host.xml</code>is a good place for shared resources like authentication, database poolsor host-wide <a href="resin-ioc.xtp">beans and services</a>. It's also alocation for the <host-alias> in a dynamic hosting configuration.</p><p>The <code>host.xml</code> is configured in a <host-deploy>or <host-default> by adding a<a href="env-tags.xtp#import"><resin:import></a> tagspecifying the host.xml name and location. Because the <host-default>applies the <resin:import> to every virtual host, it becomes a commonsystem-wide configuration file.</p></s2><s2 title="web-applications"><p>Hosts must define <a href="webapp-tags.xtp">web-apps</a> in order toserve files, servlets, or PHP pages. If the host is missing allwebapps, Resin will return <code>404 Not Found</code> for all requestsmake to the host.</p><p>Both explicit <a href="webapp-tags.xtp#web-app"><web-app></a> anddynamic <a href="webapp-tags.xtp#web-app-deploy">web-app-deploy</a> tagsare used to configure webapps. The explicit style is generally used forApache-style configuration, while the dynamic style is generally used forJava app-server .war configuration.</p><p>Remember, Resin's default servlets like the file, JSP, and PHP servletsalso need to be defined before they're used. So all Resin configurationfiles need to have a <resin:import> of the <code>conf/app-default.xml</code>configuration file either in the <cluster> or in ashared <cluster-default>. If the app-default.xml is missing, Resin willnot serve static files, JSP, or PHP, and will not even look in theWEB-INF for resin-web.xml, classes, or lib.</p></s2></s1><s1 title="IP-Based Virtual Hosting"><p>While Resin's virtual hosting is primarily aimed at named-basedvirtual hosts, it's possible to run Resin with IP-Based virtual hosts.</p><p>With IP virtual hosting, each <http> block is configuredwith the virtual host name. This configuration will override anyvirtual host supplied by the browser.</p><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"><p>Resin's virtual hosting understands host names encoded usingrfc3490 (Internationalizing Domain Names in Applications). This supportshould be transparent. Just specify the virtual host as usual, andResin will translate the brower's encoded host namethe unicode string.</p><p>Support, of course, depends on the browser. <a href="http://devedge.netscape.com/viewsource/2003/idn/">Mozilla 1.4</a> supports the encoding.</p></s1><s1 title="Virtual Hosts with Apache or IIS"><p>A common configuration uses virtual hosts with Apache or IIS.As usual, Apache or IIS will pass matching requests to Resin.</p><s2 title="Apache"><p>The Resin JVM configuration with Apache is identical to thestandalone configuration. That similarity makes it easy to debug theApache configuration by retreating to Resin standalone if needed.</p><p>The <var>ServerName</var> directive in Apache is vital to make Resin'svirtual hosting work. When Apache passes the request to Resin, ittells Resin the <var>ServerName</var>. Without the <var>ServerName</var>,Resin can get very confused which host to serve.</p><example title="httpd.conf">LoadModule caucho_module /usr/local/apache/libexec/mod_caucho.soResinConfigServer 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 beforethe ResinConfigServer for Apache to properly understand theResinConfigServer command. If they're missing, Apache will sendan error.</note></s2><s2 title="Apache front-end"><p>The host-specific back-end JVMs are ready to receive requests on their srunports. Apache is the front-end server, and is configured to dispatch to theappropriate back-end Resin JVM for the host: </p><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><p>When you restart the Apache web server, you can look at<var>http://gryffindor/caucho-status</var>and <var>http://slytherin/caucho-status</var> to checkyour configuration. Check that each virtual host is using theserver <var>address</var> and <var>port</var> that you expect.</p></s2><s2 title="IIS"><p>Configuration and installation for IIS virtual sites is discussed in the <a href="install-iis.xtp">IIS installation</a> section.</p></s2></s1> <!-- with Apache or IIS --><s1 title="Testing virtual hosts"><p>During development and testing, it is often inconvenient or impossible touse real virtual host names that are registered as internet sites, and resolveto an internet-available IP address. OS-level features on the test clientmachine can be used to map a virtual host name to an IP address. </p><p>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 tocomputer that the client is running on.</p><p>Unix user's edit the file <code>/etc/hosts</code>:</p><example title="/etc/hosts">127.0.0.1 localhost127.0.0.1 www.gryffindor.com127.0.0.1 www.slytherin.com</example><p>Windows user edit the file <code>C:\WINDOWS\SYSTEM32\DRIVERS\ETC\HOSTS</code>:</p><example title="C:\WINDOWS\SYSTEM32\DRIVERS\ETC\HOSTS">127.0.0.1 localhost127.0.0.1 www.gryffindor.com127.0.0.1 www.slytherin.com</example></s1> </body></document>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -