如题,在配好了tomcat之后
server.xml(部分)
 <Connector port="8081" 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="Catalina" defaultHost="localhost" jvmRoute="jvm1">         
    --> 
    <Engine name="Catalina" defaultHost="localhost">      <!--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"/>
      -->              <!-- Use the LockOutRealm to prevent attempts to guess user passwords
           via a brute-force attack -->
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <!-- 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"/>
      </Realm>      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">        <!-- 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
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"  
               prefix="localhost_access_log." suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" resolveHosts="false"/>      </Host>
启动花生壳,路由的虚拟服务没有配置,现在已经可以用花生壳的域名+端口通过外网访问tomcat了
http://XXXXX:8081
1、我看到网上许多教程说要配置路由的虚拟服务,而且tomcat配置里的localhost改成域名,这个地方不理解?
2、现在外网访问的时候是加上端口8081才能访问的,而我的路由的虚拟服务里面有这么几项虚拟服务名称

 内网主机IP地址 
 192.168.1._
 协议 tcp

 外部端口 _

 内部端口 _
我想问那个外部端口和内部端口有什么作用,如果外部端口改成80,内部端口改成8081的话,是不是外网通过域名(http://XXXXXX)不用加端口就可以访问我的tomcat了
 它的工作原理是不是这样: 外网(http://XXXXXX)→路由虚拟服务(外部端口80)→路由虚拟服务(内部端口8081)3、如果路由虚拟服务的原理是这样的话,又存在了一个问题,我的IIS端口是8089(因为80端口被http.exe占了),我在虚拟服务里面增加了一条内网主机IP地址 
 192.168.1._
 协议 tcp

 外部端口 80

 内部端口 8089
的记录,然后外网通过域名(不加端口)是不能访问我的IIS的,现在问题就出来了,那么路由的虚拟服务到底是作什么用的呢?它的那两个端口又是作什么用的呢?4、最后还有一个问题,http.exe占用了我的80端口,网上说这是apache服务,那么我用apache tomcat的话,我的tomcat就必须用其他的端口了,如果路由的虚拟服务不能我猜想的那个原理的话,外网如何能不加端口访问的tomcat和iis呢?
求技术高手解答,这个问题困扰我很久了。

解决方案 »

  1.   

    1、我看到网上许多教程说要配置路由的虚拟服务,而且tomcat配置里的localhost改成域名,这个地方不理解?
    —— 这里主要是为了防止一些带域名跳转的情况,还有需要查询域名的情况;虽然不常用,但改成域名会稳妥些。2、我想问那个外部端口和内部端口有什么作用,如果外部端口改成80,内部端口改成8081的话,是不是外网通过域名(http://XXXXXX)不用加端口就可以访问我的tomcat了
    —— 你说的是一个作用;另一个作用是如果你没有将自己主机作为DMZ主机的话,这种路由端口映射是唯一的能将你机器的服务暴露到外网去的方法。(不经过路由而直接用主机拨号上网不在此列)3、如果路由虚拟服务的原理是这样的话,又存在了一个问题,我的IIS端口是8089(因为80端口被http.exe占了),我在虚拟服务里面增加了一条
    —— 简单点理解,就是个端口映射,或者理解为端口转发;好处就是可以把内网很多台机器的不同端口暴露出去;比如A机器的8080端口,暴露为外网的80;B机器的8080端口,暴露为外网的81;C机器的....4、最后还有一个问题,http.exe占用了我的80端口,网上说这是apache服务
    —— 可以用Apache做Tomcat的反向代理服务,也就是所有请求先由Apache服务接收,然后再根据context_path转发给不同的Tomcat服务器甚至IIS服务器。
      

  2.   

    1、如果我有多个域名,tomcat配置里的localhost改成域名,那么其他的域名怎么访问tomcat?
    2、我的IIS端口是8089,然后我在路由的虚拟服务配置增加了一条
    内网主机IP地址
     192.168.1._
     协议 tcp 外部端口 80 内部端口 8089
    但是我通过http://XXXX不能访问到iis下的项目,还是只能通过http://XXXX:8089才能访问,但是我换成tomcat的话,tomcat的端口是8081,路由虚拟配置改成
    内网主机IP地址
     192.168.1._
     协议 tcp 外部端口 80 内部端口 8081
    就可以通过http://XXXX访问tomcat了,为什么iis不可以而tomcat可以呢?这种路由端口映射是唯一的能将你机器的服务暴露到外网去的方法。我当时第一次配置的时候并没有配置路由的虚拟服务,外网也是可以同通过域名:端口访问我的IIS项目的,这好像有有点冲突了?
      

  3.   

    1、如果我有多个域名,tomcat配置里的localhost改成域名,那么其他的域名怎么访问tomcat?
    —— 没记错的话,Tomcat支持多个域名,只不过一个是主域名(default)而已,其它是别名;具体配置可能要Google下了。
    2、我当时第一次配置的时候并没有配置路由的虚拟服务,外网也是可以同通过域名:端口访问我的IIS项目的,这好像有有点冲突了?
    —— 根据你描述的情况来看,应该是你自己的主机配置成DMZ主机了,也就是只要路由上没有配置过的任何端口收到来自互联网的请求,都直接转发给你主机的对应端口。如果内网就你自己的主机需要提供服务,这是比较方便的,不过相当于把你的整台电脑暴露在互联网上,变成肉鸡的概率是相当高的。
    —— 所以最好取消DMZ主机设置,然后老老实实的用端口映射。
    最后,如果多个应用服务器想共用一个 外网端口,就在主机上装个Apache负责做分发吧。