`
victorwmh
  • 浏览: 207666 次
  • 性别: Icon_minigender_1
  • 来自: 宇宙
社区版块
存档分类
最新评论

tomcat https配置

 
阅读更多

 

1、生成证书

   # JAVA_HOME/bin/keytool -genkey -alias tomcat -keyalg RSA  -keystore D:\WebKit\tomcat.keystore 

   执行该命令行后,会有一堆名称、区域、位置、证书密码等参数要你输入,测试的话其他参数无所谓,但证书密码要记住,tomcat配置中需要使用。

 

 

2、配置HTTPS

   打开tomcat目录conf下的server.xml文件,找到关于ssl设置的相关段。

 

 <!--
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
               maxThreads="150" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" />
-->
    

   去掉注释,增加keystoreFile和keystorePass属性,修改为:

 

<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
               maxThreads="150" scheme="https" secure="true"
               clientAuth="false" keystoreFile="D:\WebKit\tomcat.keystore"
               keystorePass="111111" sslProtocol="TLS" />
      

 

   重启Tomcat,https就配置完成。

 

 

3、强制HTTPS访问

 

   在tomcat/conf/web.xml或项目Web-inf/web.xml中的</welcome-file-list>后面加上以下配置:

<login-config>  
	<!-- Authorization setting for SSL -->  
	<auth-method>CLIENT-CERT</auth-method>  
	<realm-name>Client Cert Users-only Area</realm-name>  
</login-config>  
<security-constraint>  
	<!-- Authorization setting for SSL -->  
	<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/conf/web.xml中修改,则所有的项目都强制用HTTPS访问;而在Web-inf/web.xml中修改,则只强制该项目用HTTPS访问。

 

    注:若https端口配置为其它端口,记得修改http转接端口。

 

<Connector port="8090" protocol="HTTP/1.1"   
        	connectionTimeout="20000"   
        	redirectPort="8443" URIEncoding="UTF-8" />  

 

 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics