背景:據說17年蘋果app必須走https協議與后台交互了,網上各種搜索最后還是發現有2篇寫的比較全面,折騰后總結出2種實現方式.在這里記錄,方便有共同需求的同學們參考
本文只介紹生成自簽名ssl證書 為網站添加https訪問 第三方免費ssl簽名(startssl)及tomcat配置請點這里
自簽名方式比較簡單只需2步:如下
第一步 用jdk自帶的keytool 生成證書文件
jdk的bin目錄下有個keytool命令
命令行 keytool -genkeypair -alias "myssl" -keyalg "RSA" -keystore "D:\Program Files\Java\myssl.keystore"
具體步驟如下:

第二步 配置tomcat(主要是修改server.xml文件 重點加了keystoreFile和keystorePass 屬性。注釋的部分是原有的,如下圖)
<!-- Define a SSL HTTP/1.1 Connector on port 8443 This connector uses the BIO implementation that requires the JSSE style configuration. When using the APR/native implementation, the OpenSSL style configuration is required as described in the APR/native documentation --> <!-- <Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol" maxThreads="150" SSLEnabled="true" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" /> --> <Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol" maxThreads="150" SSLEnabled="true" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" keystoreFile="D:\Program Files\Java\myssl.keystore" keystorePass="mykeystore" />
修改完成保存並退出,重啟tomcat 在地址欄用https訪問對應端口

點擊繼續前往可進入目標頁面,如下圖

參考網站:http://blog.csdn.net/jimmy609/article/details/18557955
