Tomcat 8.5 configure Https

Tips before viewing:

The JDK version used in this article is 1.7.0_80, and the Tomcat version is 8.5.34.

1. Generate a digital certificate

Here we use the keytool.exe that comes with jdk to generate, and the directory where my keytool.exe is D:\Program Files\Java\jdk1.7.0_80\bin(under the bin directory of jdk)

Open cmd and use the keytool command to generate a certificate (if environment variables are not configured, you need to execute the command in the bin directory of jdk)

Insert picture description here

keytool -genkey -v -alias tomcat -keyalg RSA -keystore E:\apache-tomcat-8.5.34\conf\key\tomcat.keystore -validity 365

Insert picture description here
Insert picture description here
The digital certificate is successfully generated.

2. Configure Tomcat's server.xml file

Modify the configuration in server.xml, my server.xml file path is E:\apache-tomcat-8.5.34\conf(under the tomcat conf directory)

Insert picture description here

search for

<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol" maxThreads="150" SSLEnabled="true">

Uncomment this code and modify it as follows

	<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
               maxThreads="150" SSLEnabled="true" 
			   keystoreFile="E:\apache-tomcat-8.5.34\conf\key\tomcat.keystore" keystorePass="12345678">
        <!--
		<SSLHostConfig>
            <Certificate certificateKeystoreFile="conf/localhost-rsa.jks"
                         type="RSA" />
        </SSLHostConfig>
		-->
    </Connector>

Insert picture description here
Or modify to the following configuration

	<Connector port="443" protocol="org.apache.coyote.http11.Http11NioProtocol"
               maxThreads="150" SSLEnabled="true">
        
		<SSLHostConfig>
            <Certificate certificateKeystoreFile="E:\apache-tomcat-8.5.34\conf\key\tomcat.keystore"
                         certificateKeystoreType="JKS"  certificateKeystorePassword="12345678"/>
        </SSLHostConfig>
		
    </Connector>

Insert picture description here

Start Tomcat, the results are as follows
Insert picture description here
, the 8080 page of the original http can be accessed
Insert picture description here

==Note:== If you change 8443 to another port, the 8443 port of the following code also needs to be modified

 <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

Insert picture description here
Modify port 8443 in the following code segment to a consistent port.

Guess you like

Origin blog.csdn.net/weixin_43611145/article/details/105087822