手机版
你好,游客 登录 注册
背景:
阅读新闻

Tomcat下为每个Web应用配置不同的访问端口

[日期:2012-06-05] 来源:Linux社区  作者:jiangtongcn [字体:大 中 小]

2、重复步骤一再次创建一个Service

<Servicename="Catalina.app2">

    <Connector port="8082"protocol="HTTP/1.1"

              connectionTimeout="20000"

               redirectPort="8443"/>

    <Engine name="Catalina.app2" defaultHost="localhost">

      <RealmclassName="org.apache.catalina.realm.LockOutRealm">       

        <RealmclassName="org.apache.catalina.realm.UserDatabaseRealm"

               resourceName="UserDatabase"/>

      </Realm>

      <Host name="localhost"  appBase="webapps"

            unpackWARs="true"autoDeploy="true">      

        <ValveclassName="org.apache.catalina.valves.AccessLogValve"directory="logs"

               prefix="localhost_access_log."suffix=".txt"

               pattern="%h %l %u %t&quot;%r&quot; %s %b" />

                   <Context path="/"docBase="app2" />

      </Host>       

    </Engine>

 </Service>

 

3、启动Tomcat,观察日志输出

 

信息: Deploying webapplication directory E:\WorkSpace\JavaWorkspace\Tomcat 7.0\webapps\app1

2012-6-414:03:36 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info

信息: Parsingconfiguration file [struts-default.xml]

2012-6-414:03:37 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info

信息: Parsingconfiguration file [struts-plugin.xml]

2012-6-414:03:37 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info

信息: Parsingconfiguration file [struts.xml]

2012-6-414:03:38 org.apache.catalina.startup.HostConfig deployDirectory

信息: Deploying webapplication directory E:\WorkSpace\JavaWorkspace\Tomcat 7.0\webapps\app2

2012-6-414:03:39 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info

信息: Parsingconfiguration file [struts-default.xml]

2012-6-414:03:39 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info

信息: Parsingconfiguration file [struts-plugin.xml]

2012-6-414:03:39 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info

信息: Parsingconfiguration file [struts.xml]

 

4、通过浏览器访问:

         http://localhost:80801/index.jsp

         我们通过观察浏览器发出的请求头如下:

Request URL: http://localhost:8081/index.jsp

Request Method:GET

Status Code:200 OK

Request Headersview source

Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Accept-Charset:GBK,utf-8;q=0.7,*;q=0.3

Accept-Encoding:gzip,deflate,sdch

Accept-Language:zh-CN,zh;q=0.8

Cache-Control:max-age=0

Connection:keep-alive

Cookie:JSESSIONID=CADAAC6E5B9366F4590E50B889BE58BF

Host:localhost:8081

Pragma:no-cache

User-Agent:Mozilla/5.0 (Windows NT 5.1)AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.168 Safari/535.19 QIHU360EE

Response Headersview source

Content-Length:1235

Content-Type:text/html;charset=UTF-8

Date:Mon, 04 Jun 2012 06:24:19 GMT

Server:Apache-Coyote/1.1

Set-Cookie:JSESSIONID=BA86EAD5BBDF7BB51343377C88588AB8;Path=/; HttpOnly

 

         请注意红色的部分就是主机头,一般是Internet域名。

 

         http:// localhost:80802/ognl.jsp

         这里和上面做法一样,主机头是:Host:localhost:8082

5、观察Tomcat的conf目录:

        

         你发现了什么?????????????????????????????????????

         Catalina.app1和Catalina.app2是我们分别配置的两个Engine的名字。打开这两个目录,我们发现:

        

         里面都有个localhost,其实这是我们上面配置的虚拟主机名称,如果你配置的虚拟主机名称是qrkx.uten.cn,那么这里目录的名称就是qrkx.uten.cn了。

 

         注意:如果你的Webapps目录下有ROOT目录请将其更名或删除,否则访问地址:http://localhost:8081和http://localhost:8082是会出问题的。官方文档有这样的说明:If the contextPath is a zero length string, the base name isROOT

linux
本文评论   查看全部评论 (1)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款
第 1 楼
* 匿名 发表于 2013/5/15 8:35:33
说的太好了,还是linux好。