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:
run cmd as an administrator to enter and
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
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
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:
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.
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):
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.