Tomcat opens HTTPS service

Source: Internet
Author: User

First, create a certificate

The certificate is an important key in the single sign-on authentication system, the client's mutual security on the server is the certificate; This tutorial is a demonstration so you can use the JDK's own keytool tool to generate the certificate, if you really want to use in the product environment to buy the certificate provider, Certificate certification is generally certified by VeriSign, Chinese official website: http://www.verisign.com/cn/

Generate the certificate with the Keytool tool that comes with the JDK:

Open command line interface, input: keytool-v-genkey-alias tomcat-keyalg rsa-keystore d:/tomcat.keystore-validity 36500

D:/tomcat.keystore is to place the generated tomcat.keystore under the D-Packing directory.

The meaning of "-validity 36500" is the certificate validity period, 36500 means 100 years, and the default value is 90 days.

The following is the process of the command, the main need to remember the keystore password.

Enter KeyStore Password:
Enter the new password again:
What is your first and last name?
[Unknown]: Gradven
What is the name of your organizational unit?
[Unknown]: gradven.com
What is your organization's name?
[Unknown]: gradven.com
What is the name of your city or region?
[Unknown]: Hangzhou
What is the name of your state/province?
[Unknown]: zhejaing
What is the two-letter country/region code for this unit?
[Unknown]: CN
Cn=gradven, ou=gradven.com, o=gradven.com, L=hangzhou, St=zhejiang, C=CN correct
?
[No]: Yes

Enter into the D-packing directory to see the generated tomcat.keystore.

Ii. Configuring Tomcat

Go to the Tomcat folder
Find the Sever.xml in the Conf directory and edit it

Edit
<connector port= "8443" protocol= "http/1.1" sslenabled= "true"
maxthreads= "Scheme=" "https" secure= "true"
Clientauth= "false" keystorefile= "D:/apachesoftwarefoundation/apache-tomcat-6.0.3/conf/tomcat.keystore"
keystorepass= "123456" sslprotocol= "TLS"/>
Note:
The keystorepass password in the parameter is the "123456" that we just set.

Then reboot tomcat and use https://127.0.0.1:8443 to access the page, which can be accessed.

Finally, in the application, add the Web. xml:

<security-constraint>        <web-resource-collection >                < Web-resource-name >SSL</web-resource-name>                <url-pattern>/*</url-pattern>         </web-resource-collection>                                      <user-data-constraint>                <transport-guarantee>confidential</ transport-guarantee>        </user-data-constraint> < /security-constraint>

Tomcat opens HTTPS service

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.