Configure HTTPS requests in Tomcat

Source: Internet
Author: User

I. Creating a TOMCAT Certificate

This uses the Keytool tool that comes with the JDK to generate the certificate:

1. Open Keytool.exe under the JDK's installation directory \bin\keytool.exe

2. Enter the following command at the command line:

Keytool-genkeypair-alias "Tomcat"-keyalg "RSA"-keystore "G:\tomcat.keystore"  

The above command will produce a pair of asymmetric keys and self-signed certificates G:\tomcat.keystore

Note: "First and last name" should be the domain name, lost to the name, and the real run time domain name does not match, will be problematic

Here I enter the password is 123456, the domain name is tomcat for example, provinces and cities in Guangdong Shenzhen as an example

Two. Configuring the Tomcat Server

Locate the installation directory for the Tomcat server and locate the Server.xml file under Conf

Find the following code that has been commented:

1 <!--2     <connector port= "8443" protocol= "http/1.1" sslenabled= "true" 3                maxthreads= "$" scheme= "https" Secure= "true" 4                clientauth= "false" sslprotocol= "TLS"/>5--     

Remove the comment and modify it to:

1 <connector port= "8443" protocol= "http/1.1" sslenabled= "true"  2               maxthreads= "" scheme= "https" secure= " True "  3               clientauth=" false "sslprotocol=" TLS "   4        keystorefile=" G:\tomcat.keystore "  5        keystorepass= "123456"/>  

On the Internet, the default port for the HTTP protocol is 443, and the default port for HTTPS is 443.

Three. Start the Tomcat server

Enter: Https://localhost in IE browser

Choose to continue browsing this site

It's done!!!!

Problems encountered:

I am in the process of configuring the problem, when I modified the Server.xml configuration, start tomcat error

 1 Org.apache.catalina.core.StandardService initinternal 2 Critical: Failed to initialize connector [connector[http/1.1-443]] 3 Org.apache.catalina.LifecycleException:Failed to initialize component [connector[http/1.1-443]] 4 at Org.apache.catalina.util.LifecycleBase.init (lifecyclebase.java:106) 5 at Org.apache.catalina.core.StandardService.initInternal (standardservice.java:559) 6 at Org.apache.catalina.util.LifecycleBase.init (lifecyclebase.java:102) 7 at Org.apache.catalina.core.StandardServer.initInternal (standardserver.java:814) 8 at Org.apache.catalina.util.LifecycleBase.init (lifecyclebase.java:102) 9 at Org.apache.catalina.startup.Catalina.load (catalina.java:633) at Org.apache.catalina.startup.Catalina.load ( catalina.java:658) at Sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) Sun.reflect.NativeMethodAccessorImpl.invoke (nativemethodaccessorimpl.java:57) at Sun.reflect.DelegatingMethodAccessorImpl.invoke (delegatingmethodaccessorimpl.java:43) at Java.lang.reflect.Method.invoke (method.java:606) at Org.apache.catalina.startup.Bootstrap.load (bootstrap.java:281) Org.apache.catalina.startup.Bootstrap.main (bootstrap.java:455) caused by: Org.apache.catalina.LifecycleException:Protocol Handler initialization Failed18 at Org.apache.catalina.connector.Connector.initInternal (connector.java:983) at Org.apache.catalina.util.LifecycleBase.init (lifecyclebase.java:102) 20 ...  MORE21 caused by:java.lang.Exception:Connector attribute sslcertificatefile must be defined when using SSL with APR22 At Org.apache.tomcat.util.net.AprEndpoint.bind (aprendpoint.java:507) Org.apache.tomcat.util.net.AbstractEndpoint.init (abstractendpoint.java:610) at Org.apache.coyote.AbstractProtocol.init (abstractprotocol.java:429) at Org.apache.catalina.connector.Connector.initInternal (connector.java:981) 26 ... More

Online to find the next, you can replace the protocol= "http/1.1" with Protocol= "Org.apache.coyote.http11.Http11Protocol", the problem can be resolved

Four. Install the Tomcat certificate in the browser

Here the browser shows a certificate error with a red warning

In the browser, right-click the Select property to view the certificate

Here I created a new hello.html page in the root directory of Tomcat in order to export the certificate

The following can be accessed to

Export the certificate to

Note: This place has some of the computer's "Copy Files" button is not point, do not come out

Try to install a virtual machine.

Here's the next step.

I exported the certificate to the desktop,

A certificate file for a CER was obtained

Open your browser's Internet options below----> content----> Certificates

Select Trusted Root Certification Authorities----> Import certificates

Import the generated certificate in

The rest of the steps go directly to the next

Restart the browser and find------no red warning!!!

Get!!!

Configure HTTPS requests in Tomcat

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.