香港云服務器詳解如何給Tomcat配置https/ssl證書
創建證書
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:
這樣就會在當前目錄創建一個localhost-rsa.jks文件。密碼是123456,別名是tomcat。
給Tomcat配置證書
首先將上面生成的localhost-rsa.jks文件拷貝到Tomcat的conf目錄,然后打開該目錄下面的server.xml文件,找到如下代碼,原來是注釋了,現在需要打開注釋更改為如下內容:
然后重新啟動Tomcat,訪問https://www.enuoidc.com:8443/
就可以看到如下頁面:
sslEnabled=”true” maxThreads=”150″ scheme=”https” secure=”true”
clientAuth=”false” sslProtocol=”TLS”
keystoreFile=”conf/localhost-rsa.jks” keystorePass=”123456″
/>
可以看到地址欄是顯示為不安全的。因為這個證書是我們自己制作的,瀏覽器默認不信任他,當然你可以手動信任他。