手順
a. キーストアを作成する
コマンドプロンプトを立ち上げて、keytoolコマンドを実行する【構文】 "%JAVA_HOME%\bin\keytool" keytool -genkey -alias [証明書の名称] -keyalg RSA -keystore [ファイル名] -validity [有効日数] 【コマンド例】 "%JAVA_HOME%\bin\keytool" -genkey -alias tomcat -keyalg RSA -keystore demo.keystore -validity 3650
b.TomcatのSSLコネクタを有効にする
[b-1] 「a. キーストアを作成する」で作成したキーストアファイルをTomcat配下に置く → 例「C:\pg\apache-tomcat-8.5.3\conf\demo.keystore」 [b-2] 「【Tomcatがある環境】\apache-tomcat-X.X.XX\conf\server.xml」をエディタで開く → 例「C:\pg\apache-tomcat-8.5.3\conf\server.xml」をメモ帳で開く [b-3] 以下を追加(「Connector port="8443"」などで検索すればヒットすると思うので、その付近に追加)■構文
<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol" maxThreads="150" SSLEnabled="true"> <SSLHostConfig hostName="localhost"> <Certificate certificateKeystoreFile="【キーストアファイルの位置】" certificateKeystorePassword="【キーストアファイルのパスワード】" certificateKeyAlias="【キーストア内での証明書の名称】" certificateKeystoreProvider="SUN" certificateKeystoreType="JKS" type="RSA" /> </SSLHostConfig> </Connector>* 修正例:server.xml
<!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443 This connector uses the NIO implementation with the JSSE engine. When using the JSSE engine, the JSSE configuration attributes must be used. --> <!-- <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol" maxThreads="150" SSLEnabled="true"> <SSLHostConfig> <Certificate certificateKeystoreFile="conf/localhost-rsa.jks" type="RSA" /> </SSLHostConfig> </Connector> --> <!-- ★ここから★ --> <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol" maxThreads="150" SSLEnabled="true"> <SSLHostConfig hostName="localhost"> <Certificate certificateKeystoreFile="conf/demo.keystore" certificateKeystorePassword="changeit" certificateKeyAlias="tomcat" certificateKeystoreProvider="SUN" certificateKeystoreType="JKS" type="RSA" /> </SSLHostConfig> </Connector> <!-- ★ここまで★ --> <!-- Define a SSL/TLS HTTP/1.1 Connector on port 8443 with HTTP/2 This connector uses the APR/native implementation. When using the APR/native implementation or the OpenSSL engine with NIO or NIO2 then the OpenSSL configuration attributes must be used. -->
c.確認としてブラウザで以下のURLにアクセスする
[[https://localhost:8443/]]* Tomcat画面が表示されてたらOK