美文网首页
tomcat-ssl证书

tomcat-ssl证书

作者: 开水_duyl | 来源:发表于2019-08-11 18:02 被阅读0次

    tomcat-ssl证书

    创建证书

    注意 :下面的是实验使用的,真实环境下需要去购买证书

    $ keytool -genkeypair -alias "tomcat" -keyalg "RSA" -keystore "localhost-rsa.jks"

    Enter keystore password: #输入密钥存储库密码:
    Re-enter new password: #重新输入新密码:
    What is your first and last name? #你的姓和名是什么?
    [Unknown]: pich
    What is the name of your organizational unit? #您的组织单位的名称是什么?
    [Unknown]: pich
    What is the name of your organization? #您的组织名称是什么?
    [Unknown]: tomcat
    What is the name of your City or Locality? #你的城市或地区叫什么名字?
    [Unknown]: beijing
    What is the name of your State or Province? #你的州或省叫什么名字?
    [Unknown]: beijing
    What is the two-letter country code for this unit? #这个单位的国家代码是什么?
    [Unknown]: cn
    Is CN=pich, OU=pich, O=tomcat, L=beijing, ST=beijing, C=cn correct? #问你上方的输入正确吗
    [no]: y
    Enter key password for <tomcat> #输入<tomcat>的密钥密码
    (RETURN if same as keystore password):
    Re-enter new password:

    首先将上面生成的localhost-rsa.jks文件拷贝到Tomcat的conf目录,然后打开该目录下面的server.xml文件,

    
    
    
    ### 修改配置文件
    
    
    # 打开server.xml配置文件默认是注释的需要打开,端口默认是8443我修改成了443
        <Connector port="443" protocol="org.apache.coyote.http11.Http11NioProtocol"                          SLEnabled="true"
                   maxThreads="150" scheme="https" secure="true"
                   clientAuth="false" sslProtocol="TLS"
                   keystoreFile="conf/localhost-rsa.jks"      #证书的路径
                   keystorePass="123456"                      #创建证书时的密码
                />
    
    #这样设置还不行需要设置一个跳转,只要访问80端口就转发到443端口,端口号初始时8080是我改成了80端口
        <Connector port="80" protocol="org.apache.coyote.http11.Http11NioProtocol"
                       connectionTimeout="20000"
                       redirectPort="443" />     #转发到443端口
    
    

    设置强制使用https访问

    修改配置文件 conf /web.xml

    在<web-app></web-app>中,</welcome-file-list>之后添加
    

    <login-config>

    <auth-method>CLIENT-CERT</auth-method>
    <realm-name>Client Cert Users-only Area</realm-name>
    </login-config>
    <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的域名
    
    
    #添加本地解析
     vim /etc/hosts
     
    #绑定配置文件tomcat 下的 conf /server.xml
      修改内容一:
         <Engine name="Catalina" defaultHost="www.aaa.com">       #绑定地址名 
      
      修改内容二:
          <Host name="www.aaa.com"  appBase="webapps"            #www.aaa.com就是我设置的域名 
                unpackWARs="true" autoDeploy="true">
     
    

    重新启动tomcat访问就可以看到效果了

    相关文章

      网友评论

          本文标题:tomcat-ssl证书

          本文链接:https://www.haomeiwen.com/subject/capsjctx.html