How to Configure SSL/TLS for Apache Tomcat

Apache Tomcat or Tomcat server is powerful, open-source Java Servlet Container that implements multiple Java EE specs including JavaServer Pages (JSP), Java Servlet, WebSocket, and Java EL. The application powers large-scale, mission-critical systems in a wide range of well-respected organizations and industries. If your organization is using Tomcat server chances are, you are handling sensitive data. One of the best ways to provide optimal security to the data you process is installing SSL/HTTPS.

Apache Tomcat supports the Secure Socket Layer (SSL) protocol which is good news, but the bad news is that the configuration process can be a little overwhelming for newbies. Our comprehensive guide is assembled to help you configure HTTPS in Tomcat server in no time.

Ready? Let’s get started!


  • Tomcat
  • Java SDK

Step 1: Create a Keystore

The first step when configuring HTTPS on Apache Tomcat is creating and editing a file known as the keystore. This is a very important file where will store all the keys used for SSL configuration. The file can be created using two ways:

  • Creating a new key or,
  • Sending an existing key to your keystore

For the sake of this guide, we’ll focus on generating a new key using an application called the keytool. Depending on the computer you are using open the terminal using the command:

  • For Windows: cd %JAVA_HOME/bin
  • For Mac OS or Linux: cd $JAVA_HOME/bin

Run the command below:

"%JAVA_HOME%\bin\keytool" -genkey -alias tomcat -keyalg RSA
  -keystore \path\to\my\keystore

Make sure to substitute the appropriate syntax for your operating system (OS) and use your ideal Keystore path> and Alias.

Next, you will be requested to provide a password for your keystore. Select a strong password and keep it secure (don’t forget the password). Provide the correct answer to all the questions:

Note:  I have used strongpass as my password.

The keytool will create a file (.keystore) on the user home directory. The following will be the location of the file:

  • Windows: C: Docs and settings [username]
  • Mac: /users/ [username]
  • Linux : /home/ [username]

Step 2: Create the CSR

Once you have created the keystore, the next step is generating the CSR. The CSR is what your Certificate Authority (CA) will use to create the SSL certificate. You can leverage the power of the Java Keytool to generate the CSR, as well. Run the following command:

$JAVA_HOME/bin/keytool -certreq -keylag RSA -alias -file.csr -keystroke [path/to/your/keystore]

A file yourcertificatename.csr will be created. The file should be submitted to your Certificate Authority; the CA will use the file to create your unique certificate which can u be downloaded using the given instructions.

Step 3: Install the SSL certificate

SSL automatically authenticates the validity of a website’s certificate using “trust chain”. It initiates an extra handshake via your CA as specified in the site’s certificate.

Next, download your Root Certificate; from the Certificate Authority. This certificate helps you anchor the certificate’s trust chain. Import the certificate together with the new site’s certificate into the keystore. Your Certificate Authority avails instructions to download your Root Certificate.

To import your Root Certificate use the following command:

keytool -import -alias root -keystore [path/to/your/keystore] -trustcacerts -file [path/to/the/root_certificate

Next import the new certificate using the command below:

$keytool-import -alias [youralias] -keystore [path/to/your/keystore] -file [path/to/your_keystore]

Once that is done, you can rest assured that your keystore is fully functional and certified. You can now proceed to the next step.

Step 4: Configure Apache Tomcat to utilize the Secure Socket Layer

The first thing when directing Tomcat server to utilize SSL is configuring its SSL connectors.

In the text editor open:


The connector of interest is the one on port number 8443. To locate the connector, you should search for the following line: <! – – Define a SSL HTTP/1.1 Connector on port 8443 in:

The comment that encloses the connector provides a choice between the JSSE and Apache Portable Runtime (APR) configurations. It refers to SSL implementation we intend to use, JSSE (Apache Tomcat’s Default Configuration).

Do you know what APR is? If no, replace the entry with the command below, to enable Tomcat server to find the keystore:

<connector port="8443" maxthreads="150" scheme="https" secure="true"
SSLEnabled="true" keystoreFile="path/to/your/keystore"
keystorePass="yourKeystorePassword" ClientAuth="false" keyAlias="yourAlias"

On the other hand, if you are experienced and know how APR works this option will work for you. The APR also was known as Tomcat’s native library is the best practice especially if you are using Tomcat as a standalone server.

Modify the entry as follows to enable Apache Tomcat to utilize the APR OpenSSL instead of JSSE:

<connetcor port="8443" scheme="https" secure="true" SSLEnabled="true"
SSL CertificateFile+'/path/to/your/certificate.crt"
SSLCertificateChaineFile="path/to/your/root/certificate" KeyaAlias="yourAlias"

When using APR, the “SSLCertificateKey” and “SSLCertificateFile” attributes should replace the KeystoreFile attribute.

Next, restart the Tomcat and open https://localhost:8443 in your browser to confirm HTTPS/SSL setup. The page should open over the secure HTTPS protocol.

Step 6: Limit SSL usage

The final step is limiting SSL usage. When you enable SSL/HTTPS in Apache Tomcat server.xml file it configures all files to run as both safe and insecure pages. This can cause unwanted server load, which can affect the performance of your system. For this reason, it’s wise to select the application that should offer secure SSL connections. Add the following element <security-constraint> to the WEB-INF/web.xml file:

<web-resource-name> yourAppsName</web-resource-name>

This sets all SSL options for all your pages in a centralized place. To disable the SSL for all the pages, replace the “CONFIDENTIAL” with “NONE”.

Another important thing is specifying the implementation you want to use if you have installed connectors for JSSE and APR. Tomcat utilizes APR by default, but you can make it use JSSE by adjusting an attribute of the connector’s protocol as follows;

<connector protocol="org.apache.coyote.http11.HTTP11NioProtocol">

To force it to use APR, use the following command:

<connectore protocol="org.a[ache.coyote.http11AprProtocol">


During your operation (SSL configuration) you may encounter some errors if the settings such as aliases and keystore passwords are not entered correctly. Some of these setting’s values are case-sensitive and should be used as set.


Check out the top 3 Best web hosting services

$2.49 /mo
Starting price
Visit HostArmada
Rating based on expert review
  • User Friendly
  • Support
  • Features
  • Reliability
  • Pricing
$4.00 /mo
Starting price
Visit Kamatera
Rating based on expert review
  • User Friendly
  • Support
  • Features
  • Reliability
  • Pricing
$2.00 /mo
Starting price
Visit Hostens
Rating based on expert review
  • User Friendly
  • Support
  • Features
  • Reliability
  • Pricing

How to use SSH to Back Up Your WordPress Website Hosted on a Linux VPS

The default directory path for websites in Linux Servers is usually./var/www/htm
1 min read
Idan Cohen
Idan Cohen
Marketing Expert

How to Install a Self-Signed SSL Certificate on Your Ubuntu 18.04 VPS or Dedicated Server

This how-to article will teach you how to create a self-signed SSL certificate o
3 min read
Michael Levanduski
Michael Levanduski
Expert Hosting Writer & Tester

How To Set Up SSH for an Ubuntu 16.04 VPS From a Linux Client

How to set up ssh private key authentication on an Ubuntu 16.04 server with a Li
2 min read
Max Ostryzhko
Max Ostryzhko
Senior Web Developer, HostAdvice CTO

How To Transfer Files From a Remote Server to another Remote Server Using SSH

A relatively common situation is requiring the move of a website from one server
4 min read
Eliran Ouzan
Eliran Ouzan
Web Designer & Hosting Expert provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.