码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-02-28 18:52:19      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:恶意解析

2015.02.27 

突然同事反应,在百度上搜索其他域名,竟然打开了和我们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.com  appBase="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>


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

标签:恶意解析

原文地址:http://tericut.blog.51cto.com/642105/1616008

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!