tomcat 域名配置

tomcat 域名 :

TOMCAT的域名配置2010-10-19 17:28现在很多的公司的网站都是用tomcat作为应用服务区的,可是对于初学者,8080端口号是如何去掉的,这些网站是如何和域名绑定到一起的呢?一个 tomcat是如何绑定多域名?并且这些域名是如何对应不同的项目呢?而且我的服务器没放在机房,放在我的本地,我应该如何把我的服务器给映射到外网?这一系列的问题,今天就这个问题,我来说一下。
1. 域名。现在的域名不是很贵,有很多人都有,而我们注册域名的网站也会有一个DNS助解析,就是把服务器的IP绑定到这些域名上。
2. 我们域名有了,现在就来说说我们的项目;比如说我现在有两个项目都在我的这个tomcat下面。那我们输入http://localhost:8080 /abc就可以访问到我们abc这个项目了,但是端口号8080如何去掉呢?在tomcat的conf文件夹下有一个server.xml。我们打开这个文件,找到8080,只需要把8080改成80即可。当我们再次输入http://localhost/abc即可。
3. 可是我们的域名如何跟项目绑定到一起呢?我们再次找到tomcat下面的conf文件夹里面的server.xml。修改<Host name="我们所要绑定的域名" debug="0" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"></Host>
4. 当启动tomcat的时候,输入我们绑定的域名,是不是看到了我们的tomcat。可是我们想访问我们的项目还得再域名后面加上项目名称才能访问到,也就是说到现在我们的域名还没跟项目绑定到一起。我们在看一下第三部,想让我们的项目和域名绑定到一起,我们只需要在</Host>前面加上<Context docBase="项目名" path="" reloadable="true" >即可。
例如:<Host name="www.abc.com" debug="0" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"><Context docBase="baidu" path="" reloadable="true" ></Host>
5. 当我们的有两个项目都放在同一个tomcat下的时候,我们只需要把<Host></ Host>加上两个既可以完成我们的2个项目的绑定,但是项目名称别忘了改哦。
6. 当我们的服务器自己维护(没有放在机房),我们需要对我们的路由做一下映射。就拿我的路由来举例。我的路由是TP-LINK WR340G型号,进入路由后,我们能找到一个转发规则,那里面有一个虚拟服务器的这项,点击新增条目以后会有:服务端口号、IP地址、协议、状态、常用服务端口号。我们只需在这里IP地址(服务器的局域网IP),协议选择ALL(有的路由好像没有这项,那就不需要填写了),状态选择生效,常用服务端口号选择HTTP或者WEB即可。这时默认的端口号为80。当常用服务端口号没有HTTP或者WEB这项时,可以选择DNS,然后手动把端口号改成80。点击生效。保存即可。如果说本人说的路由映射对您不适用或者没有看明白,可以上网找各种路由的映射方法。
7. 这个时候我们在输入我们的域名,是不是就直接访问到我们的项目了。

转载某某的……
 

 Tomcat配置一个ip绑定多个域名2009-07-02 11:36本人对tomcat下配置 一ip对多域名的方法详细如下,按下面配置一定能成功,经过测试了.

<Host name="localhost" debug="0" appBase="D:\\Tomcat 5.0\\webapps"
       unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">
       <Alias>localhost.com</Alias>
       <Logger className="org.apache.catalina.logger.FileLogger"
                 directory="logs" prefix="localhost_log." suffix=".txt"
            timestamp="true"/>
        <Context path="" docBase="D:\\Tomcat 5.0\\webapps\\gg" reloadable="true" caseSensitive="false" debug="0"></Context>
</Host>

<Host name="one.localhost" debug="0" appBase="D:\\Tomcat 5.0\\webapps"
       unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">
       <Alias>one.localhost.com</Alias>
       <Logger className="org.apache.catalina.logger.FileLogger"
                 directory="logs" prefix="localhost_log." suffix=".txt"
            timestamp="true"/>
       <Context path="" docBase="D:\\Tomcat 5.0\\webapps\\kk\\a" reloadable="true" caseSensitive="false" debug="0"></Context>
</Host>

<Host name="two.localhost" debug="0" appBase="D:\\Tomcat 5.0\\webapps"
       unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">
       <Alias>two.localhost.com</Alias>
       <Logger className="org.apache.catalina.logger.FileLogger"
                 directory="logs" prefix="localhost_log." suffix=".txt"
            timestamp="true"/>
        <Context path="" docBase="D:\\Tomcat 5.0\\webapps\\kk\\b" reloadable="true" caseSensitive="false" debug="0"></Context>
</Host>

因无域名解析服务器,所以在hosts上配,来模拟dns解析.

10.1.1.241 localhost           指向gg文件夹
10.1.1.241 localhost.com       指向gg文件夹
10.1.1.241 one.localhost       指向a文件夹
10.1.1.241 one.localhost.com   指向a文件夹
10.1.1.241 two.localhost       指向b文件夹
10.1.1.241 two.localhost.com   指向b文件夹

经过多方面尝试,终于在tomcat下配置成功了.


修改默认的应用时:改defaulthost,并将context的path置为空。

配置多个应用时:

如:http://localhost:8080/

        http://localhost:8080/first

        http://localhost:8080/second

对应的配置如下:

<Host name="localhost" debug="0" appBase="D:\\Tomcat 5.0\\webapps"
       unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">
       <Alias>localhost.com</Alias>
       <Logger className="org.apache.catalina.logger.FileLogger"
                 directory="logs" prefix="localhost_log." suffix=".txt"
            timestamp="true"/>
        <Context path="" docBase="D:\\Tomcat 5.0\\webapps\\Root" reloadable="true" caseSensitive="false" debug="0"></Context>

        <Context path="/first" docBase="D:\\Tomcat 5.0\\webapps\\first" reloadable="true" caseSensitive="false" debug="0"></Context>
        <Context path="/second" docBase="D:\\Tomcat 5.0\\webapps\\second" reloadable="true" caseSensitive="false" debug="0"></Context>
</Host>
 

 

 


tomcat下servlet.xml文件配置域名2010年04月15日 星期四 下午 03:10<?xml version='1.0' encoding='utf-8'?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- Note: A "Server" is not itself a "Container", so you may not
     define subcomponents such as "Valves" at this level.
     Documentation at /docs/config/server.html
-->
<Server port="8005" shutdown="SHUTDOWN">

<!--APR library loader. Documentation at /docs/apr.html -->
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
<Listener className="org.apache.catalina.core.JasperListener" />
<!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html -->
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />

<!-- Global JNDI resources
       Documentation at /docs/jndi-resources-howto.html
-->
<GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>

<!-- A "Service" is a collection of one or more "Connectors" that share
       a single "Container" Note: A "Service" is not itself a "Container",
       so you may not define subcomponents such as "Valves" at this level.
       Documentation at /docs/config/service.html
   -->
<Service name="Catalina">

    <!--The connectors can use a shared executor, you can define one or more named thread pools-->
    <!--
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="150" minSpareThreads="4"/>
    -->
   
   
    <!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
         Java AJP Connector: /docs/config/ajp.html
         APR (HTTP/AJP) Connector: /docs/apr.html
         Define a non-SSL HTTP/1.1 Connector on port 8080
    -->
    <Connector port="80" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443"   />
    <!-- A "Connector" using the shared thread pool-->
    <!--
    <Connector executor="tomcatThreadPool"
               port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443"    />
    -->          
    <!-- Define a SSL HTTP/1.1 Connector on port 8443
         This connector uses the JSSE configuration, when using APR, the
         connector should be using the OpenSSL style configuration
         described in the APR documentation -->
    <!--
    <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
               maxThreads="150" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" />
    -->

    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />


    <!-- An Engine represents the entry point (within Catalina) that processes
         every request. The Engine implementation for Tomcat stand alone
         analyzes the HTTP headers included with the request, and passes them
         on to the appropriate Host (virtual host).
         Documentation at /docs/config/engine.html -->

    <!-- You should set jvmRoute to support load-balancing via AJP ie :
    <Engine name="Standalone" defaultHost="localhost" jvmRoute="jvm1">        
    -->
    <Engine name="Catalina" defaultHost="www.meemei.com">

      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html (simple how to)
          /docs/config/cluster.html (reference documentation) -->
      <!--
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->      

      <!-- The request dumper valve dumps useful debugging information about
           the request and response data received and sent by Tomcat.
           Documentation at: /docs/config/valve.html -->
      <!--
      <Valve className="org.apache.catalina.valves.RequestDumperValve"/>
      -->

      <!-- This Realm uses the UserDatabase configured in the global JNDI
           resources under the key "UserDatabase". Any edits
           that are performed against this UserDatabase are immediately
           available for use by the Realm. -->
      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
             resourceName="UserDatabase"/>

      <!-- Define the default virtual host
           Note: XML Schema validation will not work with Xerces 2.2.
       -->
 

<Host name="x593106671.gicp.net" appBase="webapps"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false">
<Alias>x593106671.gicp.net</Alias>
<Alias>xiaojunwei.gicp.net</Alias>
<Alias>meemei.com</Alias>


<Context path="" docBase="D:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\meemei" debug="0"/>
     
        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
        -->

      </Host>


    </Engine>
</Service>
</Server>
 

 

 

 

tomcat配置虚拟目录和域名2009-06-03 16:11在$tomcat/webapps/下建了个myjsp目录作为我网站的默认目录,在myjsp中有一个a.jsp文件,该文件要作为我网站的默认主页。

修改配置文件:

首先,修改$tomcat/conf/server.xml文件。
在server.xml文件中,有一段如下:
……
<engine name="Catalina" defaultHost="localhost改为你的域名">
   <host name="localhost改为你的域名" appBase="webapps"
       unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">
   ……
   <host>
</engine>
……
在<host></host>标签之间添加上:

<Context path="" docBase="myjsp" debug="0" reloadable="true" />

path是说明虚拟目录的名字,如果你要只输入ip地址就显示主页,则该键值留为空;

docBase是虚拟目录的路径,它默认的是$tomcat/webapps/ROOT目录,现在我在webapps目录下建了一个myjsp目录,让该目录作为我的默认目录。

debug和reloadable一般都分别设置成0和true。

更改端口
<Connector port="8080改为80或者你想要的端口" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" enableLookups="false" redirectPort="8443" acceptCount="100" debug="0" connectionTimeout="20000" disableUploadTimeout="true" />

将port "8080"改成你的端口,web服务器一般为80端口,你就改为80


然后,修改$tomcat/conf/web.xml文件。
在web.xml文件中,有一段如下:
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
在<welcome-file-list>与<welcome-file>index.html</welcome-file>之间添加上:

<welcome-file>a.jsp</welcome-file>


下面这段比较重要
〈init-param〉
〈param-name〉listings〈/param-name〉
〈param-value〉false(一定要改为false,否则输入域名不能访问)〈/param-value〉
〈/init-param〉


保存上述两个文件后重启tomcat,在浏览器地址栏内输入"http://你的域名",显示a.jsp页面的内容。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值