zoukankan      html  css  js  c++  java
  • tomcat配置https访问

    一.  创建tomcat证书

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

    1. 打开cmd,启动keytool

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

    keytool -genkeypair -alias "tomcat" -keyalg "RSA" -keystore "c:	omcat.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:	omcat.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

  • 相关阅读:
    C#中关于@的用法
    c++ 中__declspec 的用法
    #pragma详细解释(一)
    memmove 和 memcpy的区别
    【niubi-job——一个分布式的任务调度框架】----安装教程
    [异能程序员]第一章 酒后事发(第一更)
    博客园的最后一篇博文,还是要离开了(附带个人博客源码分享)
    五一假期——技术之路上的坎儿
    deerlet-redis-client添加集群支持,邀请各路大神和菜鸟加入。
    从日常开发说起,浅谈HTTP协议是做什么的。
  • 原文地址:https://www.cnblogs.com/coniglio/p/9821087.html
Copyright © 2011-2022 走看看