tomcat的安全配置(禁用http方法,部署多個應用,啟用從安全cookie,指定錯誤頁面和顯示資訊)

來源:互聯網
上載者:User

標籤:

配置版本: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>

tomcat的安全配置(禁用http方法,部署多個應用,啟用從安全cookie,指定錯誤頁面和顯示資訊)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.