resin 虚拟主机就是resin根据不同的请求的host名称,将请求分配到不同的虚拟主机上面。那边为什么同一个ip会有不同的主机域名呢?是因为http请求中有一个host名称,通过nginx可以修改这个名称,进而根据不同的请求映射到不同的虚拟主机:
上面是nginx的配置,它如果遇到类似example.com/activity/*的url,它就会设置ip数据包中的host。resin服务器接收到请求,根据请求中的host名称分配请求到不同的虚拟主机。
虚拟主机的定义方式同样有2中。一种的指定的,一种是动态的。
指定的定义方式如下:
<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>
指定的host定义通过host标签定义。
动态虚拟主机定义:
<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>
动态的虚拟主机定义标签式host-deploy
,他定义了虚拟主机的根目录。
目录格式如下:
/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