https://my.oschina.net/wangyongqing/blog/115647

Jetty用户经常想配置他们的web应用到不同的虚拟主机。
通常情况下,一个单一的IP地址的机器有不同的DNS解析名与它相关联的,部署在这个机器上的web应用必须能够通过这些关联的DNS解析名访问到。

Another possibility is to serve different web applications from different virtual hosts. 另一种可能是不同的虚拟主机为不同的web应用提供服务。你可以用不同的方法设置虚拟主机,包括: 1)再context文件夹中放置一个context XML文件:setVirtualHosts. 这是一个完美的方法。 2)用java调用内嵌式jetty服务 3)再jetty.xml中明确列出要部署的项目列表或者类似的。 4)再项目的WEB-INF下面加一个自己的jetty-web.xml (在你不适用jetty提供的配置文件的情况下). 对于不同的方式来配置虚拟主机,包括文件,提供详细的配置说明的链接的说明,请参阅如何配置 jetty 下面是用第一种方法,通过调用ContextHandler.serVirtualHosts方法设置虚拟主机的实例: 实例一:配置一个虚拟主机

<!-- 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
第一次翻译文章,部分翻译内容有问题请指出!谢谢!

最新文章

  1. Ambari——大数据平台的搭建利器
  2. 响应链和UIKit框架
  3. Flex String转Date
  4. NetBeans常用快捷键
  5. CodeForceS#276-A
  6. Oracle的导入导出
  7. Windows下安装redis,并与PHP使用
  8. online learning
  9. jetty上传 Form too large: 275782 &gt; 200000
  10. vmtouch - the Virtual Memory Toucher
  11. 结对编程1——四则运算-GUI
  12. 持续集成配置之Nuget
  13. when to use reinterpret_cast
  14. jquery html 獲取或設置
  15. selenium python3
  16. spring学习 十二 AspectJ-based的通知入门 带参数的通知
  17. group by 字符串合并 有关问题
  18. SpringBoot-Mybatis_Plus学习记录之公共字段自动填充
  19. Linux文件系统操作
  20. 【DB2】查看表空间对应的物理文件地址

热门文章

  1. InnoSetup 安装选择不同语言,修改软件配置参数,达到安装语言就是软件语言效果
  2. java基础(31):网络通信协议、UDP、TCP
  3. Ubuntu个人使用笔记整理
  4. Linux中fdisk分区
  5. [日常] 解决github速度特别慢
  6. layui增删改查
  7. TeamyinyinFish-&gt;鱼嘤嘤小分队软件工程beta迭代作业
  8. DIV 自定义滚动条样式(二)
  9. 洛谷 P5594 【XR-4】模拟赛
  10. 设计模式-抽象工厂模式(AbstractFactory)(创建型模式)