实例一:配置一个虚拟主机
<!-- lang: xml -->
< Configure class = "org.eclipse.jetty.webapp.WebAppContext" >
< Set name = "contextPath" >/xxx</ Set >
< Set name = "war" >< SystemProperty name = "jetty.home" />/webapps/xxx.war</ Set >
< Set name = "virtualHosts" >
< Array type = "java.lang.String" >
< Item >333.444.555.666</ Item >
< Item >127.0.0.1</ Item >
< Item >www.blah.com</ Item >
< Item >www.blah.net</ Item >
< Item >www.blah.org</ Item >
</ Array >
</ Set >
</ Configure >
如果你配置了jetty监听到8080端口,你可以通过如下方式访问到xxx.war
http://333.444.555.666:8080/xxx
http://127.0.0.1:8080/xxx
http://www.blah.com:8080/xxx
http://www.blah.net:8080/xxx
http://www.blah.org:8080/xxx
实例二:配置不用的虚拟主机用不同的contextPath
<!-- lang: xml -->
< Configure class = "org.eclipse.jetty.webapp.WebAppContext" >
< Set name = "contextPath" >/xxx</ Set >
< Set name = "war" >< SystemProperty name = "jetty.home" />/webapps/xxx.war</ Set >
< Set name = "virtualHosts" >
< Array type = "java.lang.String" >
< Item >333.444.555.666</ Item >
< Item >127.0.0.1</ Item >
< Item >www.blah.com</ Item >
< Item >www.blah.net</ Item >
< Item >www.blah.org</ Item >
</ Array >
</ Set >
</ Configure >
<!-- lang: xml -->
< Configure class = "org.eclipse.jetty.webapp.WebAppContext" >
< Set name = "contextPath" >/zzz</ Set >
< Set name = "war" >< SystemProperty name = "jetty.home" />/webapps/zzz.war</ Set >
< Set name = "virtualHosts" >
< Array type = "java.lang.String" >
< Item >777.888.888.111</ Item >
< Item >www.other.com</ Item >
< Item >www.other.net</ Item >
< Item >www.other.org</ Item >
</ Array >
</ Set >
</ Configure >
这里需要注意的是第二个没有配置127.0.0.1,因为两个都配置了就没法区分了
应用xxx.war 通过下面能访问到:
http://333.444.555.666:8080/xxx
http://127.0.0.1:8080/xxx
http://www.blah.com:8080/xxx
http://www.blah.net:8080/xxx
http://www.blah.org:8080/xxx
应用 zzz.war 通过下面法师能访问到:
http://777.888.888.111:8080/zzz
http://www.other.com:8080/zzz
http://www.other.net:8080/zzz
http://www.other.org:8080/zzz
实例三:配置不用的虚拟主机用相同的contextPath
<!-- lang: xml -->
< Configure class = "org.eclipse.jetty.webapp.WebAppContext" >
< Set name = "war" >< SystemProperty name = "jetty.home" />/webapps/xxx.war</ Set >
< Set name = "contextPath" >/</ Set >
< Set name = "virtualHosts" >
< Array type = "java.lang.String" >
< Item >333.444.555.666</ Item >
< Item >127.0.0.1</ Item >
< Item >www.blah.com</ Item >
< Item >www.blah.net</ Item >
< Item >www.blah.org</ Item >
</ Array >
</ Set >
</ Configure >
<!-- lang: xml -->
< Configure class = "org.eclipse.jetty.webapp.WebAppContext" >
< Set name = "war" >< SystemProperty name = "jetty.home" />/webapps/zzz.war</ Set >
< Set name = "contextPath" >/</ Set >
< Set name = "virtualHosts" >
< Array type = "java.lang.String" >
< Item >777.888.888.111</ Item >
< Item >www.other.com</ Item >
< Item >www.other.net</ Item >
< Item >www.other.org</ Item >
</ Array >
</ Set >
</ Configure >
应用 xxx.war 通过如下方式访问:
http://333.444.555.666:8080/
http://127.0.0.1:8080/
http://www.blah.com:8080/
http://www.blah.net:8080/
http://www.blah.org:8080/
应用 zzz.war 通过如下方式访问:
http://777.888.888.111:8080/
http://www.other.com:8080/
http://www.other.net:8080/
http://www.other.org:8080/
原文请参考http://wiki.eclipse.org/Jetty/Howto/Configure_Virtual_Hosts
|