tomcat配置https访问

tomcat配置https访问

一.  创建tomcat证书

 

使用JDK自带的keytool工具来生成证书:

 

1. 打开cmd,启动keytool

 

2. 在命令行中输入以下命令:

keytool -genkeypair -alias "tomcat" -keyalg "RSA" -keystore "c:\tomcat.keystore" 

 

 

完成后在磁盘生成tomcat.keystore文件

 

 

二. 配置tomcat服务器

 

 定位到tomcat服务器的安装目录, 找到conf下的server.xml文件

找到如下已经被注释的代码:

 

1 <!--
2     <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" 3 maxThreads="150" scheme="https" secure="true" 4 clientAuth="false" sslProtocol="TLS" /> 5 -->

 

去掉注释,修改为:

 

1 <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" 2 maxThreads="150" scheme="https" secure="true" 3 clientAuth="false" sslProtocol="TLS" 4 keystoreFile="c:\tomcat.keystore" 5 keystorePass="123456" /> 

 强制https访问配置如下:
在 tomcat /conf/web.xml 中的 </welcome-file-list> 后面加上以下内容

复制代码
    <login-config>  
            <!-- Authorization setting for SSL -->  
            <auth-method>CLIENT-CERT</auth-method>  
            <realm-name>Client Cert Users-only Area</realm-name>  
    </login-config>  
    <security-constraint>  
            <!-- Authorization setting for SSL -->  
            <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服务器

在IE浏览器中输入: https://localhost

 

 

 

选择高级继续浏览此网站

 

Expand

keytool

Manages a keystore (database) of cryptographic keys, X.509 certificate chains, and trusted certificates.

 

Description

The keytool command is a key and certificate management utility. It enables users to administer their own public/private key pairs and associated certificates for use in self-authentication (where the user authenticates himself or herself to other users and services) or data integrity and authentication services, using digital signatures. The keytool command also enables users to cache the public keys (in the form of certificates) of their communicating peers.

A certificate is a digitally signed statement from one entity (person, company, and so on.), that says that the public key (and some other information) of some other entity has a particular value. (See Certificate.) When data is digitally signed, the signature can be verified to check the data integrity and authenticity. Integrity means that the data has not been modified or tampered with, and authenticity means the data comes from whoever claims to have created and signed it.

The keytool command also enables users to administer secret keys and passphrases used in symmetric encryption and decryption (DES).

The keytool command stores the keys and certificates in a keystore. See KeyStore aliases.

--https://docs.oracle.com/javase/8/docs/technotes/tools/windows/keytool.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

三省同学

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值