How to Setup SSL on Apache Tomcat | 10 Minute Guide

A step-by-step guide to set up an SSL with your tomcat to run it over HTTPS protocol.9 min


4
1 comment, 4 points
Setup ssl on apache tomcat in 10 minutes

TL;DR – Quickly install SSL on Apache Tomcat with this fast and easy guide. Complete setup in just 10 minutes.

This post is about configuration, if you want to configure your website to always open with https://your_any_website/App access using Tomcat.

Prerequisites [Basic Requirements]

  1. JAVA SDK/ JDK
  2. Tomcat (7+) [Apache Tomcat running]
  3. Admin access to Tomcat (Depending on your environment)

What is SSL and Why Tomcat Needs It

SSL — Secure Sockets Layer is a protocol that is used to secure communication between web browsers (clients) and Servers. In real time, it encrypts data exchanged between the client and the server. It also ensures that sensitive information like credit card numbers, passwords, etc. remain private and safe from third-party people, and they cannot see it directly. 

Remember that, nowadays, SSL has been replaced by TLS (Transport Layer Security), but SSL is still widely used.

As you know, the Tomcat is an open source web server, and it hasa  servlet container that needs SSL to secure its website or web app. Any data sent between the user’s end and Tomcat without SSL could be intercepted or altered by malic*ous third-party. If you implement the SSL, Tomcat will ensure that,

  1. Data is encrypted for security.
  2. User privacy is protected.
  3. Websites appear trustworthy (HTTPS instead of HTTP).

In short summary, SSL helps Tomcat to deliver secure, encrypted connections, protecting both server data and user information.

The setup consists of 3 basic steps:

  1. Create a Keystore file using Java
  2. Configure Tomcat to use the Keystore
  3. Test what you did!
  4. (Bonus ) Configure your app to work with SSL (access through https://localhost:8443/your_Application)

Apache Tomcat SSL Configuration Guide: Enable HTTPS Using Keystore | Image by Author Created with Canva

Step 1 — Creating a Keystore file using Java

First, open the terminal on your computer and type:

Windows:

cd %JAVA_HOME%/bin

Linux or Mac OS:

cd $JAVA_HOME/bin

The $JAVA_HOME on Mac is located on “/System/Library/Frameworks/JavaVM.framework/Versions/{your java version}/Home/

You will change the current directory to the directory Java is installed on your computer. Inside the Java Home directory, cd to the bin folder. Inside the bin folder, there is a file named keytool. This Thing is responsible for generating the Keystore file for us.

Next, type on the terminal:

keytool -genkey -alias tomcat -keyalg RSA

When you type the command above, it will ask you some questions. First, it will ask you to create a password (My password is “password“):

c:/RaxTonProduction/: keytool -genkey -alias tomcat -keyalg RSA
Enter keystore password:  password (it will be invisible)
Re-enter new password: password
What is your first and last name?
  [Unknown]:  Rakshit Shah
What is the name of your organizational unit?
  [Unknown]:  RaxTon
What is the name of your organization?
  [Unknown]:  RaxTon
What is the name of your City or Locality?
  [Unknown]:  Ahmedabad
What is the name of your State or Province?
  [Unknown]:  GJ
What is the two-letter country code for this unit?
  [Unknown]:  IN
Is CN=Rakshit Shah, OU=RaxTon, O=RaxTon, L=Ahmedabad, ST=GJ, C=IN correct?
  [no]:  yes
 
Enter key password for
    (RETURN if same as keystore password):  password
Re-enter new password: password

It will create a .keystore file on your user's home directory. On Windows, it will be on: C:Documents and Settings[username]; on Mac it will be on /Users/[username] and on Linux will be on /home/[username].

Step 2 — Configuring Tomcat for using the Keystore file — SSL config

Open your Tomcat installation directory and open the conf folder. Inside this folder, you will find the server.xml file. Open it.

Find the following declaration:


Uncomment it and modify it to look like the following:

Connector SSLEnabled="true" acceptCount="100" clientAuth="false"
    disableUploadTimeout="true" enableLookups="false" maxThreads="25"
    port="8443" keystoreFile="/Users/loiane/.keystore" keystorePass="password"
    protocol="org.apache.coyote.http11.Http11NioProtocol" scheme="https"
    secure="true" sslProtocol="TLS" />

Note we add the keystoreFile, keystorePass and changed the protocol declarations.

Step 3 — Let’s test it!

Start tomcat service and try to access https://localhost:8443. You will see Tomcat’s local home page.

Note if you try to access the default 8080 port it will be working too: http://localhost:8080

Step 4 — BONUS — Configuring your app to work with SSL (access through https://localhost:8443/yourApp)

To force your web application to work with SSL, you simply need to add the following code to your web.xml file (before web-app tag ends):

<security-constraint>
    
        securedapp
        /*
    
    
        CONFIDENTIAL
    

The URL pattern is set to /* so any page/resource from your application is secure (it can be only accessed with HTTPS). The transport guarantee tag is set to CONFIDENTIAL to make sure your app will work on SSL.

If you want to turn off the SSL, you don’t need to delete the code above from web.xml, simply change CONFIDENTIAL to NONE.

Bingo! You did it!

Reference: APACHE TOMCAT, Cover Image prepared by Author on Powerpoint.


Don't miss : Convert .pfx to .crt and .key: Quick and Easy Method

If you find joy and value in what I do, please consider supporting my work with a donation — however much you can afford, it means and helps more than you can imagine. Buy Me A Coffee.

Common Errors While Configuring SSL on Apache Tomcat (And How to Fix Them):

Even after following all the above given steps correctly, you might still face issues while enabling HTTPS in Apache Tomcat. Here I mentioned the common errors which are the most common SSL configuration errors developers search for, along with clear fixes.

1. HTTPS Is Not Working After Configuration

Problem:
Tomcat starts normally, but accessing https://yourdomain:8443 does not load.

Possible causes:

  • SSL connector is misconfigured in server.xml
  • Tomcat is running on a different port
  • Keystore path is incorrect

Fix:

  • Double-check the configuration in server.xml
  • Ensure SSLEnabled=”true” is present
  • Verify the keystoreFile path is correct and accessible
  • Restart Tomcat after every change (Do not forget it)

Also, confirm that - no syntax errors exist in the XML file. Even a small typo can break SSL loading overall.

2) Port 8443 Is Not Opening or is refused

Problem:
The browser shows “Connection refused” or times out when accessing port 8443.

Possible causes:

  • Port 8443 is blocked by the firewall
  • Tomcat is not listening on the port
  • Another service is already using the port

Fix:

  • Check if Tomcat is listening using netstat or similar tools
  • Open port 8443 in your server firewall or security group
  • Ensure no other application is bound to the same port
  • Confirm the connector port="8443" exists in server.xml

If you are on a cloud server, also check the cloud firewall rules.

3) Keystore Password Error While Starting Tomcat

Problem:
 Tomcat fails to start and throws keystore or password-related errors.

Possible causes:

  • Incorrect keystore password
  • Keystore file is corrupted or missing
  • Password mismatch between keystore and key

Fix:

  • Ensure the password in keystorePass matches the one used during keystore creation
  • Recreate the keystore using keytool if unsure
  • Verify the keystore file location and permissions

Check Tomcat logs carefully. They usually point to the exact issue.

4) Browser Shows “Not Secure” or Certificate Warning

Problem:

When HTTPS loads, but the browser shows a security warning or “Not Secure” label.

Possible causes:

  • Self-signed certificate
  • Certificate does not match the domain
  • Missing intermediate certificates

Fix:

  • For production, use a trusted CA-issued certificate
  • Ensure the certificate domain matches the URL
  • Import the full certificate chain into the keystore
  • Clear browser cache and test again

Self-signed certificates are fine for local testing, but not recommended for live or prod environments.

5) Changes Not Reflecting After SSL Configuration

Problem:
When SSL changes do not apply even after updating configuration files.

Possible causes:

  • Tomcat was not restarted
  • Wrong server.xml file edited
  • Cached configuration

Fix:

  • Fully stop and restart Tomcat, do not just reload
  • Confirm you are editing the correct Tomcat instance
  • Review catalina.out or Tomcat logs for startup errors


Discover more from 9Mood

Subscribe to get the latest posts sent to your email.


Like it? Share with your friends!

4
1 comment, 4 points

What's Your Reaction?

Lol Lol
0
Lol
WTF WTF
0
WTF
Cute Cute
1
Cute
Love Love
1
Love
Vomit Vomit
0
Vomit
Cry Cry
0
Cry
Wow Wow
1
Wow
Fail Fail
0
Fail
Angry Angry
0
Angry
Rakshit Shah

Explorer

Hey Moodies, Kem chho ? - Majama? (Yeah, You guessed Right! I am from Gujarat, India) 25, Computer Engineer, Foodie, Gamer, Coder and may be a Traveller . > If I can’t, who else will? < You can reach out me by “Rakshitshah94” on 9MOodQuoraMediumGithubInstagramsnapchattwitter, Even you can also google it to see me. I am everywhere, But I am not God. Feel free to text me.

One Comment

Leave a Reply

Choose A Format
Story
Formatted Text with Embeds and Visuals
List
The Classic Internet Listicles
Ranked List
Upvote or downvote to decide the best list item
Open List
Submit your own item and vote up for the best submission
Countdown
The Classic Internet Countdowns
Meme
Upload your own images to make custom memes
Poll
Voting to make decisions or determine opinions
Trivia quiz
Series of questions with right and wrong answers that intends to check knowledge
Personality quiz
Series of questions that intends to reveal something about the personality
is avocado good for breakfast? Sustainability Tips for Living Green Daily Photos Taken At Right Moment