一个虚拟主机是一个为IP地址在DNS注册的可选择的名字。一个ip地址可以很多这样选择的名字。多址主机,是一个机器有多个网络接口,每个ip地址有一个不同的名字。这也叫做“虚拟主机“。本质上,“虚拟主机“涉及到DNS注册名字到IP地址的解析 - 多个IP地址可以解析到同一个IP地址,一个或多个IP地址可能在同一个物理机器上。Jetty用户经常想配置他们的应用程序而考虑这些不同的虚拟主机。通常是一个IP地址,有很多DNS解析的名字指向它,一个布置在上面的程序所有的名字都可以访问到它。另一种可能性就是不同的虚拟主机服务于不同的应用程序。让我们检查这种可能性。
配置虚拟主机
当我们配置一个应用程序的时候,我们可以提供一个可以访问的IP地址和名字的列表,假设我们有一个机器有如下的IP地址和DNS解析的名字:
333.444.555.666
127.0.0.1
www.blah.com
www.blah.net
www.blah.org
假设我们有一个web程序,xxx.war我们想让这个程序服务所有上面的名字和IP地址,那我们将会这样配置web应用程序:
- <New class="org.mortbay.jetty.webapp.WebAppContext">
-
<Arg><Ref id="contexts"/></Arg>
-
<Arg><SystemProperty name="jetty.home">/webapps/xxx.war</Arg>
- <Arg>/xxx</Arg>
-
<Set name="defaultsDescriptor"><SystemProperty name="jetty.home" default="."/>/etc/webdefault.xml</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>
- </New>
假设我们已经配置了一监听8080端口的连接器,下面的所有地址都可以访问这个应用程序:
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
为不同的虚拟主机配置不同的程序
这个通过为每个web程序提供不同的虚拟主机列表来完成。举个例子,假设我们有个机器有如下的DNS名字和IP地址:
333.444.555.666
127.0.0.1
www.blah.com
www.blah.net
www.blah.org
777.888.888.111
www.other.com
www.other.net
www.other.org
假设我们有另一个web程序,zzz.war。我们想xxx.war还想上面的配置,但是zzz.war配置成只能从777.888.888.111, www.other.com, www.other.net 和 www.other.org来访问:
- <!-- webapp xxx.war -->
-
<New class="org.mortbay.jetty.webapp.WebAppContext">
-
<Arg><Ref id="contexts"/></Arg>
-
<Arg><SystemProperty name="jetty.home">/webapps/xxx.war</Arg>
- <Arg>/xxx</Arg>
-
<Set name="defaultsDescriptor"><SystemProperty name="jetty.home" default="."/>/etc/webdefault.xml</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>
- </New>
-
- <!-- webapp zzz.war -->
-
<New class="org.mortbay.jetty.webapp.WebAppContext">
-
<Arg><Ref id="contexts"/></Arg>
-
<Arg><SystemProperty name="jetty.home">/webapps/zzz.war</Arg>
- <Arg>/zzz</Arg>
-
<Set name="defaultsDescriptor"><SystemProperty name="jetty.home" default="."/>/etc/webdefault.xml</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>
- </New>
程序仍然在下列地址可用:
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
为不同的虚拟主机配置不同的程序,但是有相同的上下文路径
在上面的例子中,我们不只让程序zzz.war在这些虚拟主机上可用,也同时确定了上下文路径zzz,同时我们其它的程序也是在不同的虚拟主机和不同的上下文上可用。如果我们想让这些虚拟主机使用相同的上下文改怎么办呢?非常简单, 我们仅仅需要为每个程序提供相同的上下文路径,保留以上其它定义就可以了:
- <New class="org.mortbay.jetty.webapp.WebAppContext">
-
<Arg><Ref id="contexts"/></Arg>
-
<Arg><SystemProperty name="jetty.home">/webapps/xxx.war</Arg>
- *<Arg>/</Arg>*
-
<Set name="defaultsDescriptor"><SystemProperty name="jetty.home" default="."/>/etc/webdefault.xml</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>
- </New>
-
-
<New class="org.mortbay.jetty.webapp.WebAppContext">
-
<Arg><Ref id="contexts"/></Arg>
-
<Arg><SystemProperty name="jetty.home">/webapps/zzz.war</Arg>
- *<Arg>/</Arg>*
-
<Set name="defaultsDescriptor"><SystemProperty name="jetty.home" default="."/>/etc/webdefault.xml</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>
- </New>
现在, 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/
<!-- Attachments -->
分享到:
相关推荐
自己写的jetty6在eclipse启动中配置说明
JETTY启动文件配置方法.txt
tomcate和jetty虚拟目录配置方法,里面带配置文件例子
Jetty9 配置使用HTTPS证书,访问你的服务器更安全,更好的配置方法。
Jetty配置支持HTTPS以及受信网站证书生成方式
网上看到jetty-proxy有反相代理功能,根据很多网页配置并未成功,感觉是jetty版本更新比较快,文档跟不上,所以把我调试通过的上传一下。jetty版本9.4.6
Java Eclipse ee集合jetty和配置
jetty启动配置文件
简单jetty配置
NULL 博文链接:https://fuaotech.iteye.com/blog/2292707
eclipse导入即可使用jetty 。当成一个project 工程
( apache+jetty负载配置案例.zip ) 亲测可用,文档+APACHE原文件,稍做修改即可直接使用,可隐藏后端真实服务器地址,加上域名则更完美!!! 有需要的朋友自行下载使用。
jetty的xml文件配置说明
maven jetty插件配置指南。 看看就知道。
详解介绍Eclipse+maven+jetty环境配置
Jetty 配置 SSL 如何在jetty下配置SSL
springmvc+maven+ibatis+jetty的pom配置文件,平时书写太麻烦
jetty9资源通过官网下载实在太慢,为了国内程序员快速获得jetty资源,特别上jetty在idea编译器上的配置教程。
如何配置虚拟主机(Virtual Hosts) 如何配置会话ID(Session IDs) 如何序列化会话(Session) 如何重定向或移动应用(Context) 如何让一个应用响应一个特定端口 使用JNDI 使用JNDI 在JNDI中配置数据源...