http升級https

http升級https

一、註冊域名

二、添加域名解析。

 

 

三、申請ssl證書

 

進入證書服務,購買本身須要的證書,我這裏選擇的是免費證書,由於我只要測試使用。html

 

支付完以後在個人證書裏面能夠看到剛剛購買的證書。java

 

而後去裏面補全信息。而後等待審覈經過下發證書。web

四、下載證書。

 

裏面提供多種服務器的ssl證書下載以及教程,我項目所用的是tomcat服務器,因此這裏以tomcat服務爲例。apache

下載解壓獲得:(補全證書信息的時候我選擇的是系統自動生成,若是選擇的是本身生成文件會不同)windows

 

五、tomcat配置證書

先進行證書轉換tomcat

使用Java jdk將PFX格式證書轉換爲JKS格式證書(windows環境注意在%JAVA_HOME%/jdk/bin目錄下執行)服務器

Keytool -importkeystore -srckeystore 213996013500014.pfx -destkeystore your-name.jks -srcstoretype PKCS12 -deststoretype JKS

切記必定是bin文件目錄下,這裏213996013500014.pfx和your-name.jks能夠換成絕對路徑的,your-name能夠換成任意名字,不然須要將對應的文件放在bin目錄下,打開命令提示符的時候建議用管理員模式,避免沒必要要的麻煩。jsp

期間會輸入3次密碼,另外說一下,命令提示符下輸入密碼是不會在控制檯上顯示的,其實已經輸入成功了,以前還由於這個問題糾結半天,是我臺嫩了。前兩次都是輸入jks證書的密碼,本身隨意設置,第3次輸入的是pfx源文件的密碼,這個密碼在pfx-password.txt有,理論上這兩個密碼能夠不一樣,可是官方建議輸入同樣的,因此咱們就按照官方的來吧。成功以後在bin目錄下能夠找到生成的jks文件。測試

 

打開conf下的server.xml 將以下的代碼註釋去掉url

<!-- <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" maxThreads="150" 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" sslProtocol="TLS" keystoreFile="cert/xxx.jks" keystorePass="password"/>

 

其中xxx.jks爲以前證書格式轉換設置的名稱,password爲以前設置的密碼,即三次輸入那塊。 
切記在64位系統下,上面的protocol=」HTTP/1.1」 須要修改成 
「org.apache.coyote.http11.Http11Protocol」, 
這多是tomcat的bug吧,也是上網搜索的許久才找到的緣由,若是不改,啓動時候會提示錯誤。

從新啓動tomcat,在地址中輸入https://www.xxx.com:8443 其中xxx爲你的域名,你會發現成功了。

輸入https://www.xxx.com 便可訪問,不帶端口號

可是咱們想要的是不帶8443端口號的地址也能夠訪問,這裏把上面的8433改成443就能夠了,http默認端口80,https默認443,除了改好上面的,還須要更改如下兩處:

<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"

               maxThreads="150" scheme="https" secure="true"

               clientAuth="false" sslProtocol="TLS"

        keystoreFile="cert/xxx.jks"

        keystorePass="password"/>

 <Connector port="80" protocol="HTTP/1.1"

               connectionTimeout="20000"

               redirectPort="8443" />

 <Connector port="8222" protocol="AJP/1.3" redirectPort="8443" />

以上三到處8443均須要改成443;

六、域名強轉

輸入域名或者http://強制跳轉到https://服務

這裏咱們只須要修改conf文件夾下的web.xml文件

找到以下代碼片斷(在最下面)

 <welcome-file-list>

        <welcome-file>index.html</welcome-file>

        <welcome-file>index.htm</welcome-file>

        <welcome-file>index.jsp</welcome-file>

 </welcome-file-list>

在 /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>

 <welcome-file-list>

        <welcome-file>index.html</welcome-file>

        <welcome-file>index.htm</welcome-file>

        <welcome-file>index.jsp</welcome-file>

 </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>
相關文章
相關標籤/搜索