Prerequisites
The following table gives the prerequisite information that has to be complied before switching from HTTP to HTTPS for Apache Tomcat:
S.No | Dependency | Comments |
1 | JAVA | This has to be installed previously. |
2 | Apache Tomcat (8+) | This has to be installed previously. |
3 | Setting up the provided environment variables for java |
Perform the following steps in order to switch from HTTP to HTTPS for Apache Tomcat:
Step - 1: Creating a keystore file
- Open the command prompt and enter the following command:
keytool -genkey -alias tomcat -keyalg RSA -keystore canvascertificate.cert
- Enter the keystore and key password details for generating the keystore file. Here, the keystore is saved as canvascertificate.cert
Step – 2: Configuring Apache Tomcat for using keystore file — SSL config
File Location: <Tomcat-Installed-Folder>\conf \ server.xml
- Comment the following command in order to disable the default HTTP configuration:
<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
- Add the following command to enable the HTTPS configuration below the commented http configuration command.
<Connector SSLEnabled="true" acceptCount="100" clientAuth="false"
disableUploadTimeout="true" enableLookups="false" maxThreads="150"
port="9129" keystoreFile="D:\apache-tomcat-9.0.36\conf\canvascertificate.cert" keystorePass="canvas"
protocol="org.apache.coyote.http11.Http11NioProtocol" scheme="https"
secure="true" sslProtocol="TLS" />
Note:
- Make sure that you mention the Keystore path in keystoreFile field and mention the Keystore password in keystorePass field.
- Make sure that you mention the port that should be exposed for HTTPS. Here, the port number is given as 9129.
Step – 3: Accessing the Application
Start tomcat service and try to access https://localhost:9129. You will see Tomcat's local home page.