(1)在jdk的安裝目錄\bin\keytool.exe下打開keytool.exeweb
在命令行中輸入如下命令:tomcat
keytool -genkeypair -alias "tomcat" -keyalg "RSA" -keystore "E:\tomcat.keystore" -validity 36500
以上命令將生產一對非對稱密鑰和自我簽名的證書E:\tomcat.keystore服務器
注意:「名字與姓氏」應該是域名,輸成了姓名,和真正運行的時候域名不符,會出問題url
這裏我輸入的密碼是123456, 域名是以tomcat爲例, 省市以廣東深圳爲例spa
定位到tomcat服務器的安裝目錄, 找到conf下的server.xml文件命令行
找到以下已經被註釋的代碼:code
<!-- <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" />
-->
去掉註釋,修改成:server
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" maxThreads="150" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" keystoreFile="E:\tomcat.keystore" keystorePass="123456" />
在互聯網上, http協議的默認端口是80, https的默認端口是443, 這裏將端口改成了443xml
配置Tomcat,打開$CATALINA_HOME/conf/server.xml,修改以下blog
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
修改成
<Connector port="80" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="443" />
<!-- <Connector port="8009" enableLookups="false" protocol="AJP/1.3" redirectPort="8443" /> -->
修改成:
<Connector port="8009" enableLookups="false" protocol="AJP/1.3" redirectPort="443" />
在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>