1. Modify the configuration file

Open the tomcat/conf/server. XML configuration file and delete the following configuration comments. KeystorePass indicates the certificate key that needs to be manually added and is specified when the certificate is created.

<Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"
               maxThreads="150" 
               SSLEnabled="true" 
               scheme="https" 
               secure="true"
               clientAuth="false" 
               sslProtocol="TLS"
               keystorePass="123456" />
Copy the code

2. Create a certificate

Use the KEYtool command in the JDK tool class to generate the certificate and enter the corresponding information as prompted.

C:\>keytool -genkey -alias HTTPS -keyalg RSA What is the name of your organization? What is the name of your organization? [Unknown]: Test What is the name of your city or region? What is the name of your province/city/autonomous region? What is the two-letter country/area code of the unit? Unknown: test CN=test, OU=test, O=test, L=test, ST=test, C=test [No]: y Enter the key password < HTTPS > (if it is the same as the key store password, press Enter): Enter a new password again.Copy the code

The key password is the keystorePass configuration in the configuration file.

Visit HTTPS

Can visit HTTPS project at https://localhost:8443/your-project.

This method is only suitable for local HTTPS testing, online environments require the purchase of a commercially licensed certificate, but the principle is the same.

Recommended reading

Dry goods: Free 2TB architect four-stage video tutorial

Interview: the most complete Java multithreaded interview questions and answers

Tools: Recommended an online creation flow chart, mind mapping software

Share Java dry goods, high concurrency programming, hot technology tutorials, microservices and distributed technology, architecture design, blockchain technology, artificial intelligence, big data, Java interview questions, and cutting-edge hot news.