zoukankan      html  css  js  c++  java
  • Tomcat配置https

    1、使用jdk自带工具生成证书:

    keytool -genkeypair -help
    keytool -genkeypair -alias "tomcat" -keyalg "RSA" -keystore "D:keytest omcat.keystore" 

    第一个命令是参数详解

    名字和姓氏请填写自己要部署的机器的域名或者ip

    密码请自行记住

    2、修改tomcat server.xml

      <Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>
    

      <Connector connectionTimeout="20000" port="80" protocol="HTTP/1.1" redirectPort="443"/> <Connector SSLEnabled="true" clientAuth="false" keystoreFile="D:/keytest/tomcat.keystore" keystorePass="123456" maxThreads="150" port="443" protocol="org.apache.coyote.http11.Http11Protocol" scheme="https" secure="true" sslProtocol="TLS"/> <Connector port="8009" protocol="AJP/1.3" redirectPort="443"/>

    keystorePass是你刚才填的密码,keystoreFile是你证书的路径,443是默认的https访问端口,这里的80则是默认的http访问端口,这个端口也是要配置的,不然你的tomcat在eclipse中启动完毕了还会一直等待。

    3、修改web.xml

    在web-app中加上一句

    <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>

    如此,所有的http请求也会自动转为https请求了。

    一篇博客,推荐一下:http://blog.csdn.net/gane_cheng/article/details/53001846

  • 相关阅读:
    shell 中的expect 用法
    Python下安装protobuf
    google protobuf 中的proto文件编写规则
    ubuntu 16.04 安装grpc
    python 常见的错误类型 和 继承关系
    倒排索引
    python 调用c函数
    python中的re模块,常用函数介绍
    leecode第二十二题(括号生成)
    leecode第十九题(删除链表的倒数第N个节点)
  • 原文地址:https://www.cnblogs.com/flying607/p/6669785.html
Copyright © 2011-2022 走看看