您的位置:首页 > 理论基础 > 计算机网络

tomcat的安全配置(禁用http方法,部署多个应用,启用从安全cookie,指定错误页面和显示信息)

2016-09-06 10:06 896 查看
配置版本:tomcat6

1,虚拟路径,可以配置多个host在一个tomcat中,docbase是web应用目录,此处在server.xml中添加应用配置,要让server.xml配置生效需要重启tomcat

<Host name="XXXXx" appBase="D:\webroot"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">

<Context path="/" reloadable="true" docBase="D:\webroot\xxx\WebRoot\" />

</Host>

2,禁用不需要的http方法,一般禁用delete,put,默认情况tomcat禁止了delete,put,访问返回403-forbiden,此处在web.xml的<web-app>中添加如下禁用配置,

[b]要让web.xml配置生效需要重启tomcat[/b]

<security-constraint>
<web-resource-collection>
<url-pattern>/*</url-pattern>
<http-method>PUT</http-method>
<http-method>DELETE</http-method>
<http-method>HEAD</http-method>
<http-method>OPTIONS</http-method>
<http-method>TRACE</http-method>
</web-resource-collection>
<auth-constraint>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
</login-config>

3,启用安全cookie,防止xss跨站点攻击,tomcat6开始支持此属性,此处在context.xml中添加启用配置,[b]context.xml配置即调用时生效不需要重启tomcat[/b]
http://tomcat.apache.org/tomcat-6.0-doc/config/context.html
<Context useHttpOnly="true">

4,修改tomcat版本信息,防泄漏:

1)进入apache-tomcat目录lib下,找到catalina.jar,使用压缩工具依次找到org\apache\catalina\util下的ServerInfo.properties

打开ServerInfo.properties编辑:(去掉版本信息)如下

server.info=Apache Tomcat

server.number=

server.built=

2)设置web.xml的error-page,指定返回页面。此处可在应用中配置,应用中配置则只在当前应用生效。

<error-page>

<error-code>500</error-code>

<location>/500.html</location>

</error-page>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐