https
1. Tomcat實現https協議步驟1.生成證書文件(沒有通過認證的證書)
利用jdk自帶工具生成證書文件:
keytool -genkey -alias tomcat -keyalg RSA
其中,輸入祕鑰庫的口令需要記錄下來,在tomcat的配置文件有用。
你的名字與姓氏是什麼?這裏需要填入你的域名,如:dev.mobile-oa.com.cn
生成的證書文件的名稱爲:.keystore
2. 生產環境直接通過ca認證官網,認證後,下載
3. 服務器配置證書文件
將證書文件拷貝到tomcat的conf文件夾中。
打開service.xml文件,增加如下配置:
<Connector port="8445" protocol="org.apache.coyote.http11.Http11Protocol"
maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" keystoreFile="conf/.keystore" keystorePass="123456"/>
其中,keystoreFile爲證書的位置 ,keystorePass爲生成證書時候設置的祕鑰庫口令
4. tomcat 自動跳轉到HTTPS
在項目的web.xml中加入如下的配置:
<security-constraint>
<web-resource-collection>
<web-resource-name>Getssl</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>