一個jetty部署多個專案配置之方法
阿新 • • 發佈:2019-01-29
Jetty使用者經常想配置他們的web應用到不同的虛擬主機。
通常情況下,一個單一的IP地址的機器有不同的DNS解析名與它相關聯的,部署在這個機器上的web應用必須能夠通過這些關聯的DNS解析名訪問到。
Another possibility is to serve different web applications from different virtual hosts.
?1 2 3 4 5 6 |
另一種可能是不同的虛擬主機為不同的web應用提供服務。你可以用不同的方法設定虛擬主機,包括:
1 )再context資料夾中放置一個context XML檔案:setVirtualHosts. 這是一個完美的方法。 2 )用java呼叫內嵌式jetty服務
3 )再jetty.xml中明確列出要部署的專案列表或者類似的。
4 )再專案的WEB-INF下面加一個自己的jetty-web.xml (在你不適用jetty提供的配置檔案的情況下).
對於不同的方式來配置虛擬主機,包括檔案,提供詳細的配置說明的連結的說明,請參閱如何配置
|
例項一:配置一個虛擬主機
<!-- 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
|