Tomcat implements https access

Tomcat implements https access

https is an encrypted transmission protocol, and tomcat is accessed by http by default, so how do we realize https access of tomcat? Let me introduce to you.

First we need to make sure that our computer has jdk installed

Tomcat uses https request in win10

First enter the bin directory of jdk and find the keytool) command.

img

img

Then open a command window in this directory and press Enter.

img

img

Then enter this command in the window: keytool -genkey -v -alias keystoreKey -keyalg RSA -validity 3650 -keystore D:\tomcat8\apache-tomcat-8.0.51\conf\tomcat.keystore

img

img

keytool -genkey: Automatically use the default algorithm to generate public and private keys

-alias name: give the certificate an alias, here is keystoreKey

-keyalg: The algorithm for specifying the key. If you need to specify the length of the key, you can add the keysize parameter. The default key length is 1024 bits. When using the DSA algorithm, the key length must be between 512 and 1024, and is integer multiple of 64

-validity: The valid date of the certificate, the default is 90 days, the 3650 days set here

-keystore: The parameter can specify the name of the keystore. The keystore actually stores secret keys and certificate files, and stores the generated certificates in the specified directory.

Then press Enter.

img

img

The next step is to modify the tomcat configuration file. Find /conf/server.xml of tomcat, and find the following location.

img

img

After removing the comment, change it to the following information. Where keystorePass is the key password you just set. keystoreFile is the path to the certificate file just generated.

<Connector port=“8443” protocol=“org.apache.coyote.http11.Http11NioProtocol”

maxThreads=“150” SSLEnabled=“true” scheme=“https” secure=“true”

clientAuth=“false” sslProtocol=“TLS”

keystoreFile=“D:\tomcat8\apache-tomcat-8.0.51\conf\tomcat.keystore” keystorePass=“111111” />

Then save it and start tomcat. Enter https://localhost:8443/ in the browser

img

img

Because it is a self-signed certificate, the browser does not trust it, but this does not prevent us from using it.

img

img

The above are the steps to change the tomcat of win10 to https access. If it is Linux, the steps are the same as win10, but it should be noted that the format of the path is different.

Guess you like

Origin blog.csdn.net/qq_43842093/article/details/130664148