设为首页 收藏本站
查看: 333|回复: 0

[经验分享] 24 虚拟主机与Tomcat【Virtual Hosting and Tomcat】

[复制链接]

尚未签到

发表于 2017-1-22 11:09:31 | 显示全部楼层 |阅读模式
Apache Tomcat 6.0

虚拟主机与Tomcat【Virtual Hosting and Tomcat

<!--()-->目录【Table of Contents



  • 背景【Assumptions

  • server.xml
  • Web应用目录【Webapps Directory
  • 配置环境【Configuring Your Contexts

    • 综述【General】
    • context.xml 配置方法#1【context.xml - approach #1
    • context.xml 配置方法#2 【context.xml - approach #2
    • 进阶内容【Further Information





背景【Assumptions

  作为全文的背景,假设你要将你开发的应用程序映射到名叫ren和stimpy的主机名上。还要假设,有一个正在运行的Tomcat服务,$CATALINA_HOME 是对于这个服务的安装路径的引用,例如:/usr/local/tomcat。
For the sake of this how-to, assume you have a development host with two host names, ren and stimpy. Let's also assume one instance of Tomcat running, so $CATALINA_HOME refers to wherever it's installed, perhaps /usr/local/tomcat.
  另外,文中会使用unix系统的路径分隔符和命令;如果你使用的是windows系统,请自行修改。
  【Also, this how-to uses Unix-style path separators and commands; if you're on Windows modify accordingly.



server.xml

  作为最简单的方法,就是去编辑server.xml文件的Enging元素,像下面这样:
At the simplest, edit the Engine portion of your server.xml file to look like this:

http://icefox-wjx.iteye.com/admin/blogs/900683/images/void.gifhttp://icefox-wjx.iteye.com/admin/blogs/900683/images/void.gifhttp://icefox-wjx.iteye.com/admin/blogs/900683/images/void.gif
http://icefox-wjx.iteye.com/admin/blogs/900683/images/void.gif
<Engine name="Catalina" defaultHost="ren">
<Host name="ren"    appBase="renapps"/>
<Host name="stimpy" appBase="stimpyapps"/>
</Engine>

http://icefox-wjx.iteye.com/admin/blogs/900683/images/void.gif
http://icefox-wjx.iteye.com/admin/blogs/900683/images/void.gifhttp://icefox-wjx.iteye.com/admin/blogs/900683/images/void.gifhttp://icefox-wjx.iteye.com/admin/blogs/900683/images/void.gif


  注意,每个应用的appBase下的目录结构都可能不太一样。可以查看Engine和Host元素的属性的相关文档。
  【Note that the directory structures under the appBase for each host should not overlap each other.
  Consult the configuration documentation for other attributes of the Engine and Host elements.



<!--()-->Web应用目录【Webapps Directory

  为每一个虚拟主机创建如下的目录结构:
Create directories for each of the virtual hosts:

http://icefox-wjx.iteye.com/admin/blogs/900683/images/void.gifhttp://icefox-wjx.iteye.com/admin/blogs/900683/images/void.gifhttp://icefox-wjx.iteye.com/admin/blogs/900683/images/void.gif
http://icefox-wjx.iteye.com/admin/blogs/900683/images/void.gif
mkdir $CATALINA_HOME/renapps
mkdir $CATALINA_HOME/stimpyapps

http://icefox-wjx.iteye.com/admin/blogs/900683/images/void.gif
http://icefox-wjx.iteye.com/admin/blogs/900683/images/void.gifhttp://icefox-wjx.iteye.com/admin/blogs/900683/images/void.gifhttp://icefox-wjx.iteye.com/admin/blogs/900683/images/void.gif





<!--()-->配置环境【Configuring Your Contexts


综述【General

  Contexts元素通常位于appBase目录下。例如,将ren虚拟主机映射到foobar.war这个文件上,使用$CATALINA_HOME/renapps/foobar.war。虚拟主机ren的默认或者ROOT环境是$CATALINA_HOME/renapps/ROOT.war (WAR)或者 $CATALINA_HOME/renapps/ROOT (directory).
Contexts are normally located underneath the appBase directory. For example, to deploy the foobar context as a war file in the ren host, use $CATALINA_HOME/renapps/foobar.war. Note that the default or ROOT context for ren would be deployed as $CATALINA_HOME/renapps/ROOT.war (WAR) or $CATALINA_HOME/renapps/ROOT (directory).
  注意:一个主机环境下的docBase与appBase是不同的。
  NOTE: The docBase for a context should never be the same as the appBase for a host.



<!--()-->context.xml配置方法1context.xml - approach #1

  在你的环境下,创建一个META-INF目录,将你的环境上下文定义写在这个目录下的context.xml文件中。例如$CATALINA_HOME/renapps/ROOT/META-INF/context.xml 这样使得你将应用打包成一个war文件时,部署是非常容易的。
Within your Context, create a META-INF directory and then place your Context definition in it in a file named context.xml. i.e. $CATALINA_HOME/renapps/ROOT/META-INF/context.xml This makes deployment easier, particularly if you're distributing a WAR file.



<!--()-->context.xml配置方法1【context.xml - approach #2

  在$CATALINA_HOME/conf/Catalina 下创建与你的虚拟主机一致的结构,例如:
Create a structure under $CATALINA_HOME/conf/Catalina corresponding to your virtual hosts, e.g.:

http://icefox-wjx.iteye.com/admin/blogs/900683/images/void.gifhttp://icefox-wjx.iteye.com/admin/blogs/900683/images/void.gifhttp://icefox-wjx.iteye.com/admin/blogs/900683/images/void.gif
http://icefox-wjx.iteye.com/admin/blogs/900683/images/void.gif
mkdir $CATALINA_HOME/conf/Catalina/ren
mkdir $CATALINA_HOME/conf/Catalina/stimpy

http://icefox-wjx.iteye.com/admin/blogs/900683/images/void.gif
http://icefox-wjx.iteye.com/admin/blogs/900683/images/void.gifhttp://icefox-wjx.iteye.com/admin/blogs/900683/images/void.gifhttp://icefox-wjx.iteye.com/admin/blogs/900683/images/void.gif


  注意上面Catalina目录后面的目录名称,这个名字与Enging元素的name属性一致。
  【Note that the ending directory name "Catalina" represents the name attribute of the Engine element as shown above.
  现在对于你的默认应用,添加如下:
  【Now, for your default webapps, add:

http://icefox-wjx.iteye.com/admin/blogs/900683/images/void.gifhttp://icefox-wjx.iteye.com/admin/blogs/900683/images/void.gifhttp://icefox-wjx.iteye.com/admin/blogs/900683/images/void.gif
http://icefox-wjx.iteye.com/admin/blogs/900683/images/void.gif
$CATALINA_HOME/conf/Catalina/ren/ROOT.xml
$CATALINA_HOME/conf/Catalina/stimpy/ROOT.xml

http://icefox-wjx.iteye.com/admin/blogs/900683/images/void.gif
http://icefox-wjx.iteye.com/admin/blogs/900683/images/void.gifhttp://icefox-wjx.iteye.com/admin/blogs/900683/images/void.gifhttp://icefox-wjx.iteye.com/admin/blogs/900683/images/void.gif


  如果你需要使用Tomcat manager管理所有主机的web应用,你需要再进行如下操作:
  【If you want to use the Tomcat manager webapp for each host, you'll also need to add it here:

http://icefox-wjx.iteye.com/admin/blogs/900683/images/void.gifhttp://icefox-wjx.iteye.com/admin/blogs/900683/images/void.gifhttp://icefox-wjx.iteye.com/admin/blogs/900683/images/void.gif
http://icefox-wjx.iteye.com/admin/blogs/900683/images/void.gif
cd $CATALINA_HOME/conf/Catalina
cp localhost/manager.xml ren/
cp localhost/manager.xml stimpy/

http://icefox-wjx.iteye.com/admin/blogs/900683/images/void.gif
http://icefox-wjx.iteye.com/admin/blogs/900683/images/void.gifhttp://icefox-wjx.iteye.com/admin/blogs/900683/images/void.gifhttp://icefox-wjx.iteye.com/admin/blogs/900683/images/void.gif





<!--()-->进阶内容【Further Information

  请查阅Context元素的其他属性的配置文档
  【Consult the configuration documentation for other attributes of the Context element.





-------------------------------------------------------

终于在年前将Tomcat6新增的这几篇文档翻译完了,这些日子一直查看自己的博客,根本就没人看呀,呵呵,可见自己根本没有人气。要努力了。今天是大年二十九,上班的最后一天,明天放假准备过年,祝我新的一年取得理想的成绩。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-332027-1-1.html 上篇帖子: Tomcat的内存设置(Tomcat java.lang.OutOfMemoryError ) 下篇帖子: tomcat 7 源码分析-14 tomcat的container设计
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表