欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

如何在Tomcat 8.5 和 Tomcat 9 上安装 SSL 证书的简单步骤教程

最编程 2024-08-07 16:46:51
...

 

第一步:准备好所需要的证书文件,Tomcat8.5和Tomcat9部署ssl证书一般使用JKS文件,如果有Pem和key文件,也需要合成JKS文件。

第二步:打开tomcat配置文件 conf/server.xml,tomcat默认一般是8080端口或者 80端口,先找到这一段。

 

<Connector port="8080" protocol="HTTP/1.1"

	    connectionTimeout="20000"

	    redirectPort="8443" />



第三步:在这段下面插入下面配置

 

<Connector port="443"

	    protocol="org.apache.coyote.http11.Http11Nio2Protocol"

	    maxThreads="150"

	    SSLEnabled="true"
tongpeifu.cn">
tongpeifu.cn">
conf/ssl/tongpeifu.cn.jks"
123456"

	            type="RSA" />

	    </SSLHostConfig>

	</Connector>



其中代码中的443端口是默认的Https端口,也可以自定义端口, tongpeifu.jks 替换为您自己的证书文件,密码替换为您自己设定的密码。

第四步:重启Tomcat服务即可成功配置SSL证书。

如果需要在Tomcat8.5和Tomcat9版本设置强制https跳转,方法如下:

 

打开tomcat/conf/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后即可使用https访问。访问http://域名:8080也会跳转到https://域名。

 



推荐阅读