配置版本: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>中添加如下禁用配置,
要让web.xml配置生效需要重启tomcat
<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中添加启用配置,context.xml配置即调用时生效不需要重启tomcat
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>