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

 1 运维网监控突然同事反应,在百度上搜索其他域名,竟然打开了和我们P2P一模一样的网站,我第一个反应是源代码被盗用了。后来发现,是域名被恶意解析了,解决方法 1、禁止IP地址访问项目  2、只允许指定的域名访问。
 2 
 3 环境:tomcat 6
 4 方法: 修改tomcat 6 的配置文件  tomcat/conf/server.xml,实现原理,将tomcat 缺省参数defaultHost指向一个不存在的域名上,并添加同样的虚拟目录,这样当被一个未知的域名解析过来后,访问的缺省虚拟目录,但这个目录中并没有任何项目,这样就达到效果了。
 5 以下是我配置文件参数 只贴出 Engine 之间的哦~
 6 
 7 
 8 
 9 <Engine name="Catalina" defaultHost="192.168.1.1">   <!-- 缺省参数我设置的是我服务器的外网IP地址    -->
10       <!--For clustering, please take a look at documentation at:
11           /docs/cluster-howto.html  (simple how to)
12           /docs/config/cluster.html (reference documentation) -->
13       <!--
14       <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
15       -->      
16       <!-- The request dumper valve dumps useful debugging information about
17            the request and response data received and sent by Tomcat.
18            Documentation at: /docs/config/valve.html -->
19       <!--
20       <Valve className="org.apache.catalina.valves.RequestDumperValve"/>
21       -->
22       <!-- This Realm uses the UserDatabase configured in the global JNDI
23            resources under the key "UserDatabase".  Any edits
24            that are performed against this UserDatabase are immediately
25            available for use by the Realm.  -->
26       <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
27              resourceName="UserDatabase"/>
28       <!-- Define the default virtual host
29            Note: XML Schema validation will not work with Xerces 2.2.
30        -->
31       <Host name=www.abc.com  appBase="webapps" <!-- 这个虚拟目录是你真实使用的虚拟目录,域名也是你指定的域名 -->
32          unpackWARs="true" autoDeploy="true"
33          xmlValidation="false" xmlNamespaceAware="false">
34       <Context path="" docBase="/home/web/apache-tomcat-6.0.39/webapps/abc" debug="0" reloadable="true"/> <!-- 指定虚拟目录的项目地址 -->
35       </Host>
36    
37       <Host name="192.168.1.1"  appBase="ipapps"   <!-- 设置你服务器的外网IP地址,并建立一个虚假的虚拟目录  ipaaps  这个是不存在的,当访问IP地址或其他域名,将被转向到访问这个虚拟目录上 -->
38           unpackWARs="true" autoDeploy="true"
39           xmlValidation="false" xmlNamespaceAware="false">
40       </Host>
41    
42 </Engine>

 

转载于:https://www.cnblogs.com/-lpf/p/5009783.html

Spring Boot 内置的 Tomcat 服务器默认只允许通过域名访问,这是为了增强应用的安全性和防止潜在的恶意访问。这种限制是通过配置 Tomcat 的连接器实现的。 在 Spring Boot 中,可以通过配置文件或代码来实现只允许域名访问的限制。 首先,可以在 application.properties 或 application.yml(根据你使用的文件格式)中添加以下配置: ``` server.address=域名IP地址 ``` 在这个配置中,你可以指定允许访问域名IP地址(一般为本机域名IP地址),Tomcat允许通过这个域名IP地址进行访问。 如果你希望更精确地控制访问权限,可以在代码中进行配置。例如,你可以创建一个类(通常继承自 Spring Boot 的 WebSecurityConfigurerAdapter),然后重写 configure 方法,添加以下代码: ```java @Configuration public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers("/**") .hasIpAddress("指定IP地址IP地址范围") .and() .csrf() .disable(); } } ``` 在这个配置中,你可以使用 hasIpAddress 方法来指定允许访问IP地址IP地址范围。所有其他的请求将被拒绝访问。 通过以上配置,就可以让 Spring Boot 内置的 Tomcat允许通过指定域名IP地址访问,增加应用的安全性。当然,具体的配置方式还取决于你的应用需求和实际情况。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值