Java web项目 本地配置https调试

一、创建密匙

  网上有很多教程,就不在此赘述了。

  假设最后生成的密匙为tomcat.keystore 密码为123456。

二、配置tomcat

  首先,将密匙移到tomcat下根目录下。

  进入conf文件夹,配置sever.xml。

  window系统下,本地配置:

<Connector port="8080" protocol="org.apache.coyote.http11.Http11Protocol" SSLEnabled="true" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" useBodyEncodingForURI="true"
               keystoreFile="tomcat.keystore" keystorePass="123456"/>

  其中,重点为:将 protocol="HTTP/1.1" 替换为 protocol="org.apache.coyote.http11.Http11Protocol"。

  相关参数来源见如下官方网址:http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html#Configuration

三、程序HTTP自动跳转到HTTPS

  在程序中web.xml中加入:

<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均可使用。

四、最后启动项目

  使用https://127.0.0.1:8080访问页面,页面成功打开即tomcat下的https配置成功。

posted @ 2019-07-09 10:05  醉酒染青衣  阅读(1682)  评论(0编辑  收藏  举报