(首先你要有 ssl 證書 ,我是阿里的 )
查看申請ssl證書
一.下載 tomcat證書(兩個檔案)
(1.)pfx-password.txt 存放 [密碼]
(2.)xxxx.pfx 存放 證書

二.在 tomcat安裝目錄下 創建 cret 目錄,將下載的證書放在 cret 目錄下


三.在 tomcat安裝下 的 conf/server.xml 配置
(3.1) 配置 https(詳情,可能需要先登錄)
<Connector port="443"
protocol="org.apache.coyote.http11.Http11Protocol"
SSLEnabled="true"
scheme="https"
secure="true"
keystoreFile="G:/xxxxx/apache-tomcat-7.0.75/cret/xxxxx.pfx"
keystoreType="PKCS12"
keystorePass="CH7T55MI"
clientAuth="false"
SSLProtocol="TLSv1+TLSv1.1+TLSv1.2"
ciphers="TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_256_CBC_SHA256"/>

引數資訊:
port::埠號
protocol:協議規則>詳情
SSLEnabled:開啟tomcat對https支持(true/false)
scheme:協議名稱
secure:是否開啟安全訪問(true/false)
keystoreFile:秘鑰檔案路徑(即xxxx.pfx 的絕對路徑)
keystoreType:秘鑰庫型別(jks/pkcs12)
keystorePass:創建秘鑰檔案時輸入的密碼(即fx-password.txt的內容)
clientAuth:身份驗證(true/false)
SSLProtoco:ssl的協議
ciphers:密碼
(3.2) 配置http
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" URLEncoding="UTF-8"/>

引數資訊:
port: 埠號
connectionTimeout: 設定連接超時,單位毫秒 (connectionTimeout = 2000;代表超過2秒,就是超時)
protocol:協議規則>詳情
redirectPort:使用http請求某個資源,而該資源本身又被設定了必須要https方式訪問,此時Tomcat會自動重定向到這個redirectPort設定的https埠>詳情
URLEncoding:編碼格式((URL編碼),也稱作百分號編碼)
四.配置所有訪問強制轉換為 https(選配)
在 tomcat 安裝目錄 conf/web.xml 的</welcome-file-list> 之后
<login-config>
<!-- Authorization setting for SSL -->
<auth-method>CLIENT-CERT</auth-method>
<realm-name>Client Cert Users-only Area</realm-name>
</login-config>
<security-constraint>
<!-- Authorization setting for SSL -->
<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>

五.重新啟t動tomcat 即可
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/247270.html
標籤:其他
