香港云服務(wù)器詳解如何給Tomcat配置Https/ssl證書(shū)
創(chuàng)建證書(shū)
keytool -genkeypair -alias "tomcat" -keyalg "RSA" -keystore "localhost-rsa.jks"
后面的信息隨便輸入,我這里輸入的是:
Enter keystore password:
Re-enter new password:
What is your first and last name?
[Unknown]: pich
What is the name of your organizational unit?
[Unknown]: pich
What is the name of your organization?
[Unknown]: tomcat
What is the name of your City or Locality?
[Unknown]: beijing
What is the name of your State or Province?
[Unknown]: beijing
What is the two-letter country code for this unit?
[Unknown]: cn
Is CN=pich, OU=pich, O=tomcat, L=beijing, ST=beijing, C=cn correct?
[no]: y
Enter key password for
(RETURN if same as keystore password):
Re-enter new password:
這樣就會(huì)在當(dāng)前目錄創(chuàng)建一個(gè)localhost-rsa.jks文件。密碼是123456,別名是tomcat。
給Tomcat配置證書(shū)
首先將上面生成的localhost-rsa.jks文件拷貝到Tomcat的conf目錄,然后打開(kāi)該目錄下面的server.xml文件,找到如下代碼,原來(lái)是注釋了,現(xiàn)在需要打開(kāi)注釋更改為如下內(nèi)容:
然后重新啟動(dòng)Tomcat,訪問(wèn)https://www.enuoidc.com:8443/
就可以看到如下頁(yè)面:
SSLEnabled="true" maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="conf/localhost-rsa.jks" keystorePass="123456"
/>
可以看到地址欄是顯示為不安全的。因?yàn)檫@個(gè)證書(shū)是我們自己制作的,瀏覽器默認(rèn)不信任他,當(dāng)然你可以手動(dòng)信任他。