This tutorial will guide you through configuring SSL (using HTTPS protocol) on Tomcat in a matter of minutes.
I have assumed that you have already installed and are familiar with the JAVA SDK and Apache Tomcat.
For Tomcat to use HTTPS, it needs JAVA keystore. We will first generate a keystore using JAVA..
Generating a Keystore file using JAVA
- Open a terminal and navigate to the bin folder in the JAVA_HOME directory.
Use the following command,
On Linux or OSX:
cd $JAVA_HOME/binOn Windows:
We’re going to use the Keytool in this folder to generate the keystore.
2. Type the following command on the terminal to begin the keystore generating procedure.
keytool -genkey -alias tomcat -keyalg RSA
3. Enter the required details.
The keystore will now have been generated on the user home directory as .keystore.
Configuring SSL for Tomcat using the JAVA Keystore
- Navigate to the Tomcat installation directory, open the conf folder and open the server.xml file on an editor.
- Find the following commented-out XML snippet.
Uncomment the snippet and edit it in the following manner,
Enter the path of your keystore file and the keystore password to the keystoreFile and keystorePass fields respectively. Also, note the port (8443) that we will be using to access Tomcat via SSL.
That’s it! You have enabled SSL on Tomcat. Tomcat can now be accessed using the HTTPS protocol.
To test it, click on https://localhost:8443.
Tomcat will be working on the default 8080 port via the HTTP protocol too. 😄