Set up Tomcat HTTPS environment

Set up Tomcat HTTPS environment

Step 1: Generate a keystore

We use the keytool tool that comes with the JDK to generate the keystore
alias java1234 storage D:\cas\keystore
Find the directory where the keytool is located:
Insert picture description here
run cmd as an administrator to enter and
Insert picture description here
execute the following command

keytool -genkey -v -alias java1234 -keyalg RSA -keystore D:\cas\keystore\java1234.keystore

Alias: java1234 Encryption algorithm: RSA Storage location: D:\cas\keystore\java1234.keystore
Insert picture description here
Here you need to fill in some information, pay attention to fill in the domain name;
we use the keystore password666666
The execution is complete and the key library file is generated
Insert picture description here

Step 2: Export the certificate from the key store

keytool -export -trustcacerts -alias java1234 -file D:\cas\keystore\java1234.cer -keystore D:\cas\keystore\java1234.keystore

Export alias: java1234 Storage location: D:\cas\keystore\java1234.cer
Enter the keystore password of the first step666666
The certificate can be generated:
Insert picture description here

Step 3: Import the certificate into the JDK certificate library

keytool -import -trustcacerts -alias java1234 -file D:\cas\keystore\java1234.cer -keystore "C:\Program Files\Java\jdk1.8.0_212\jre\lib\security\cacerts"

Note: modify the path of the above jdk to your own jdk path.
Insert picture description here
Note that the password here is: changeit

The fourth step: tomcat configuration https support

Here use tomcat9 to
find tomcat- >conf->server.xml and open the file and
add the following configuration:

<Connector port="8543" protocol="org.apache.coyote.http11.Http11AprProtocol"
               maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
			   clientAuth="false" sslProtocol="TLS"
			   keystoreFile="D:\cas\keystore\java1234.keystore"
			   keystorePass="666666"/>
			   >

Start tomcat, the effect is as follows (note that https://localhost:8543/ needs to be used here):
Insert picture description here

Other cases

Chinese garbled characters in tomcat log
Modification: D:\000ENV\apache-tomcat-9.0.40\conf\logging.properties

#将UTF-8
java.util.logging.ConsoleHandler.encoding = UTF-8
#修改为:GBK
java.util.logging.ConsoleHandler.encoding = GBK

Just restart tomcat.

Guess you like

Origin blog.csdn.net/Asia1752/article/details/109811403