tomcat 使用https

来源:互联网 发布:数据库发展历史 编辑:程序博客网 时间:2024/06/05 22:52

1、进入jdk的bin目录

2、输入keytool -v -genkey -alias tomcat -keyalg RSA -keystore d:/tomcat.keystore  -validity 36500

附:

d:/tomcat.keystore是将生成的tomcat.keystore放到d盘根目录下。

"-validity 36500"含义是证书有效期,36500表示100年,默认值是90


3、输入keystore密码

     需要输入大于6个字符的任意密码,要记住这个密码,之后在进行server.xml配置时需要使用。


4、输入名字、组织单位、组织、市、省、国家等信息

    注意事项:
   (1)“What is your first and last name?”这是必填项,并且必须是TOMCAT部署主机的域名或者IP[如:gbcom.com 或者 10.1.25.251],就是你将来要             在浏览器中输入的访问地址
   (2)“What is the name of your organizational unit?”、“What is the name of your organization?”、“What is the name of your City or                    Locality?”、“What is the name of your State or Province?”、“What is the two-letter country code for this unit?”可以按照需要填写也可以            不填写直接回车,在系统询问“correct?”时,对照输入信息,如果符合要求则使用键盘输入字母“y”,否则输入“n”重新填写上面的信息
  (3)Enter key password for <tomcat>,这项较为重要,会在tomcat配置文件中使用,建议输入与keystore的密码一致,设置其它密码也可以
   l  完成上述输入后,直接回车则在你在第二步中定义的位置找到生成的文件

5、进入tomcat文件夹 

找到conf目录下的sever.xml并进行编辑


6、编辑 
  <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" 
     maxThreads="150" scheme="https" secure="true" 
     clientAuth="false" keystoreFile="D:/AppServer/Tomcat/apache-tomcat-6.0.32/conf/tomcat.keystore" 
     keystorePass="deleiguo" sslProtocol="TLS" /> 
注: 
方框中的keystore的密码,就是上面我们设置的密码.

编辑完成后关闭并保存sever.xml


7、Tomcat启动成功后,使用https://127.0.0.1:8443 访问页面

页面成功打开即tomcat下的https配置成功。

 

8、应用程序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>

9、如果仅需要限定部分url的访问必须通过https协议,需要在web.xml增加如下配置项。
<security-constraint> 
<web-resource-collection>
<web-resource-name>must https</web-resource-name>
<url-pattern>/test1/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
这种配置情况下,web.xml所在应用的访问url一旦是以test1开头的,均会被强迫转向https访问

0 0
原创粉丝点击