HTTPS for Tomcat web server
All applications are normally only available with the normal HTTP port on Tomcat web server. If you want to use a trusted SSL connection (HTTPS) you have to configure your Tomcat. In this article I will show you how this works and what thing you need for that. First you need to install the following things:
- JDK 1.6 of higher
- Tomcat 6 or higher
Create a keystore file
We need to navigate to the Java SDK directory:
Here you should find a keytool program. With it we can create our own keystore file:
keytool -genkey -alias ziegelwanger-edv -keypass zzadmin -keystore ziegelwanger-edv.bin -storepass zzadmin
It is important to set the same keypass and storepass. The alias and keystore filename can be defined. I used my domain. After that you have to answer some questions:
What is your first and last name?
[Unknown]: werner ziegelwanger
What is the name of your organizational unit?
What is the name of your organization?
What is the name of your City or Locality?
What is the name of your State or Province?
What is the two-letter country code for this unit?
Is CN=nitin pai, OU=home, O=techtracer, L=mumbai, ST=maharashtra, C=IN correct?
If everything worked fine you should get a ziegelwanger-edv.bin file in the same directory. We copy this file to the webapps directory of your Tomcat installation.
Configure Tomcat with your new keystore file
You can configure Tomcat by editing the server.xml file. This file can be found in your Tomcat configuration directory. On Linux this may be /etc/tomcat7/. We need to edit the connector for port 8443. Normally this connector is commented so we uncomment it and change it to fits our needs:
maxThreads=”150″ minSpareThreads=”25″ maxSpareThreads=”75″
acceptCount=”100″ debug=”0″ scheme=”https” secure=”true”
The last lines are the important ones.
You should now can connect to your application over your HTTPS port:
Configure web applications for SSL
Currently you can connect to your application with HTTP and HTTPS. If you want to only use HTTPS, you have to configure your web app. For this we have to edit the web.xml file:
You can put this line at the end of your xml file.
Done! Now your Tomcat application should be save by SSL.