1. 讓 tomcat 能使用 https
A. 在運行命令 JAVA_HOME/bin/keytool -genkey -alias tomcat -keyalg RSA -keystore C:/Tomcat /GMAE3.0Tomcat/tomcat .keystore 這樣就生成了密鑰庫,將密鑰庫放到合適的地方(任意地方都可以)
B. 打開 tomcat 目錄下的 server.xml 文件并找到關(guān)于 ssl 的相關(guān)段
2. 強制 https 訪問
在 tomcat /conf/web.xml 中的 </welcome- file-list> 后面加上這
A. 在運行命令 JAVA_HOME/bin/keytool -genkey -alias tomcat -keyalg RSA -keystore C:/Tomcat /GMAE3.0Tomcat/tomcat .keystore 這樣就生成了密鑰庫,將密鑰庫放到合適的地方(任意地方都可以)
B. 打開 tomcat 目錄下的 server.xml 文件并找到關(guān)于 ssl 的相關(guān)段
<!-- Define a SSL HTTP/1.1 Connector on port 8443 -->
<!--
<Connector port="8443" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" disableUploadTimeout="true"
acceptCount="100" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />
-->
C. 去掉注釋,添 keystoreFile="C:/Tomcat /GMAE3.0Tomcat/tomcat .keystore" keystorePass="tomcat " 的屬性,改動完成后配置為 :<!--
<Connector port="8443" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" disableUploadTimeout="true"
acceptCount="100" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />
-->
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme=" https " secure="true" clientAuth="false"
keystoreFile="C:/ Tomcat /GMAE3.0Tomcat/ tomcat .keystore"
keystorePass=" tomcat " sslProtocol="TLS" />
D. 然后重啟tomcat就能使用HTTPS訪問maxThreads="150" scheme=" https " secure="true" clientAuth="false"
keystoreFile="C:/ Tomcat /GMAE3.0Tomcat/ tomcat .keystore"
keystorePass=" tomcat " sslProtocol="TLS" />
2. 強制 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>
完成以上步驟后,在瀏覽器中輸入http的訪問地址也會自動轉(zhuǎn)換為https了<!-- 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>