http改为https免费证书

一、CMD运行以下代码:

%JAVA_HOME%\bin\keytool -genkey -alias server -keyalg RSA -keystore e:\server.keystore-validity 3650

-alias是指定一个别名,类似于Map的key
-keyalg是指定算法,默认是DSA
-keystore是生成的文件往哪里放
-validity是证书有效期,3650就是10年

或(C:“ProgramFiles”\Java\jdk1.6.0_43\bin\keytool -genkey -alias server -keyalgRSA -keystore e:\server.keystore -validity3650)(保证有e盘,如果没有改其他盘)

根据提示执行操作

二、设置的是E盘 运行完成会在E盘生成server.keystore

把server.keystore放在tomcat的根目录下

打开D:\apache-tomcat-6.0.372\conf\server.xml

新增

<Connectorport=“443” protocol=“org.apache.coyote.http11.Http11NioProtocol”

minSpareThreads="5"maxSpareThreads=“75” enableLookups="true"disableUploadTimeout=“true”

acceptCount=“100” maxThreads=“200” scheme=“https” secure=“true” SSLEnabled=“true”

clientAuth="false"sslProtocol=“TLS”

keystoreFile=“D:\apache-tomcat-6.0.372\server.keystore” keystorePass=“123456”/>

(注意红色部分)

三、修改项目中的web.xml(实现http协议跳转https协议)

增加

<security-constraint>   

       <web-resource-collection>    

              <web-resource-name>HtmlAdaptor</web-resource-name>   

              <description>An examplesecurity config that only allows users with the

              role JBossAdmin to access the HTMLJMX console web application</description>    

              <url-pattern>/</url-pattern>

              <!--<http-method>GET</http-method><http-method>POST</http-method> -->  

       </web-resource-collection>   

       <!--<auth-constraint><role-name>JBossAdmin</role-name> </auth-constraint>-->   

       <user-data-constraint>    

              <description>Protectionshould be CONFIDENTIAL</description>    

          <transport-guarantee>CONFIDENTIAL</transport-guarantee>  

       </user-data-constraint>  

</security-constraint>

server.xml配置,这步目的是让非ssl的connector跳转到ssl的connector去,redirectPort改成ssl的connector的端口443,重启后便会生效。

    <Connector port="8080" protocol="HTTP/1.1"
        connectionTimeout="20000"
        redirectPort="443" />
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值