Setup Tomcat 9 HTTPS/SSL
To have a quick view, you may see the video(s):
https://www.youtube.com/watch?v=WDGoF13vhZU
1. Generate Keystore
I am using JDK 15 to generate the keystore. But the steps are similar with Tomcat 6 + openjdk 8(as I have tried it before writing this doc)
Use “keytool” command to create a self-signed certificate.
During the keystore creation process, you need to assign a password and fill in the certificate’s details.
D:\apache-tomcat-9.0.38\conf>keytool -genkey -alias tomcatks -keyalg RSA -keystore D:\apache-tomcat-9.0.38\conf\tomcatks
When enter the passwords during generation, please make sure the two passwords you entered are
the SAME. This is the requirement of Tomcat. Here is the abstract from Tomcat installation
Finally, you will be prompted for the key password, which is the password specifically for this Certificate
(as opposed to any other Certificates stored in the same keystore file). You MUST use the same
password here as was used for the keystore password itself. This is a restriction of the Tomcat
implementation. (Currently, the keytool prompt will tell you that pressing the ENTER key does this
for you automatically.)
2. Connector in server.xml
Next, locate your Tomcat’s server configuration file at D:\apache-tomcat-9.0.38\conf\server.xml,
modify it by adding a connector element to support for SSL or https connection.
Note that if you choose HTTP/1.1 instead of org.apache.coyote.http11.Http11Protocol, just like below.
Tomcat will automatically choose the following selection based on your installation.
I failed the first time because I happened to have installed the first one (APR implementation).
Please follow the official guide for more information for APR implementation setup.
the APR implementation, which uses the OpenSSL engine by default.
the JSSE implementation provided as part of the Java runtime (since 1.4)
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="conf/tomcatks"
keystorePass="password" />
<!-- <Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol" maxThreads="150" SSLEnabled="true" > <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" /> <SSLHostConfig> <Certificate certificateKeyFile="conf/localhost-rsa-key.pem" certificateFile="conf/localhost-rsa-cert.pem" certificateChainFile="conf/localhost-rsa-chain.pem" type="RSA" /> </SSLHostConfig> </Connector> --> <Connector protocol="org.apache.coyote.http11.Http11NioProtocol" port="8443" maxThreads="200" scheme="https" secure="true" SSLEnabled="true" keystoreFile="conf/tomcatks" keystorePass="password" clientAuth="false" sslProtocol="TLS"/> <!-- Define an AJP 1.3 Connector on port 8009 --> <!-- <Connector protocol="AJP/1.3" address="::1" port="8009" redirectPort="8443" /> -->
3) Restart Tomcat
D:\apache-tomcat-9.0.38\bin>startup
Reference.
- https://tomcat.apache.org/tomcat-9.0-doc/ssl-howto.html
- https://mkyong.com/tomcat/how-to-configure-tomcat-to-support-ssl-or-https/
- http://tomcat.apache.org/tomcat-6.0-doc/ssl-howto.html#Configuration
留言
張貼留言