Home / Java Patterns and Pitfalls     frequal.com

Tomcat Https With A Self Signed Certificate

When developing web apps, frequently it's necessary to serve the web app using HTTPS. This lets non-localhost clients access the site using HTTPS, a necessity for many web APIs.

Setup

First, generate a certificate. In $TOMCAT_HOME/cert, generate the cert:
keytool -genkey -keyalg RSA -noprompt -alias tomcat -dname "CN=localhost, OU=NA, O=NA, L=NA, S=NA, C=NA" -keystore keystore.jks -validity 9999 -storepass newpass -keypass newpass
Next, add the cert to your conf/server.xml file in the Connector SSLHostConfig/Certificate:
  certificateKeystoreFile="TOMCAT_HOME/cert/keystore.jks"
  certificateKeystorePassword="newpass"
  certificateKeystoreAlias="tomcat"

Last modified on 21 May 2023 by AO

Copyright © 2024 Andrew Oliver