Switching from HTTP to HTTPS (Apache Tomcat)
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Â
1. Open the command prompt and enter the following command:
keytool -genkey -alias tomcat -keyalg RSA -keystore canvascertificate.cert
2. 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Â
1. 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" />
2. 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="...\canvascertificate.cert" keystorePass=${env.keystorePass} #Make sure environmental variable is set. Â Â Â Â protocol="org.apache.coyote.http11.Http11NioProtocol" scheme="https" Â Â Â Â secure="true" sslProtocol="TLS" />Â
- 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.