t4r23 发表于 2015-3-2 08:38:40

Tomcat6 只允许指定域名访问,禁用IP地址访问,防止恶意解析

突然同事反应,在百度上搜索其他域名,竟然打开了和我们P2P一模一样的网站,我第一个反应是源代码被盗用了。后来发现,是域名被恶意解析了,解决方法 1、禁止IP地址访问项目2、只允许指定的域名访问。

环境:tomcat 6
方法: 修改tomcat 6 的配置文件tomcat/conf/server.xml,实现原理,将tomcat 缺省参数defaultHost指向一个不存在的域名上,并添加同样的虚拟目录,这样当被一个未知的域名解析过来后,访问的缺省虚拟目录,但这个目录中并没有任何项目,这样就达到效果了。
以下是我配置文件参数 只贴出 Engine 之间的哦~



<Engine name="Catalina" defaultHost="192.168.1.1">   <!-- 缺省参数我设置的是我服务器的外网IP地址    -->
      <!--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=www.abc.comappBase="webapps" <!-- 这个虚拟目录是你真实使用的虚拟目录,域名也是你指定的域名 -->
         unpackWARs="true" autoDeploy="true"
         xmlValidation="false" xmlNamespaceAware="false">
      <Context path="" docBase="/home/web/apache-tomcat-6.0.39/webapps/abc" debug="0" reloadable="true"/> <!-- 指定虚拟目录的项目地址 -->
      </Host>
   
      <Host name="192.168.1.1"appBase="ipapps"   <!-- 设置你服务器的外网IP地址,并建立一个虚假的虚拟目录ipaaps这个是不存在的,当访问IP地址或其他域名,将被转向到访问这个虚拟目录上 -->
          unpackWARs="true" autoDeploy="true"
          xmlValidation="false" xmlNamespaceAware="false">
      </Host>
   
</Engine>
页: [1]
查看完整版本: Tomcat6 只允许指定域名访问,禁用IP地址访问,防止恶意解析