天天看點

Tomcat全局/局部https通路配置方法【tomcat容器的配置檔案web.xml中添加security-constraint】

文章來源:http://jingyan.baidu.com/article/15622f24164f7efdfdbea56b.html

Tomcat全局/局部https通路配置方法

全局https通路

  1. 1

    在Tomcat部署景安SSL證書後,如需要全局轉換成https通路,解決辦法如下:

    修改tomcat伺服器的web.xml檔案,在标記</webapp>前增加以下配置:

    <security-constraint>
    		<web-resource-collection>
    		  <web-resource-name>SSL</web-resource-name>
    		  <url-pattern>/*</url-pattern>
    		</web-resource-collection>
    		<user-data-constraint>
    		  <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    		</user-data-constraint>
    </security-constraint>
               

局部使用https通路

  1. 如果是需要局部使用https通路,解決辦法如下:
    <security-constraint>
    		<web-resource-collection>
    		  <web-resource-name>SSL</web-resource-name>
    		  <url-pattern>/test/*</url-pattern>
    		</web-resource-collection>
    		<user-data-constraint>
    		  <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    		</user-data-constraint>
    </security-constraint>
               
  2. 2

    這樣配置,當通路路徑包括test的時候,就會強制轉換為https。

注意事項

  • 根據需要,web-resource-collection節點可以配置多個,而url-pattern則配置需要強制https的url