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

  • 相关阅读:
    android应用程序的混淆打包
    sql 语句的limit的用法
    Android SDK开发包国内下载地址
    在android应用程序中启动其他apk程序
    docker+k8s基础篇五
    docker+k8s基础篇四
    docker+k8s基础篇三
    docker+k8s基础篇二
    docker+k8s基础篇一
    LVS的基础使用
  • 原文地址:https://www.cnblogs.com/coniglio/p/9821087.html
Copyright © 2011-2022 走看看