第一步:准备好所需要的证书文件,这些系列的环境版本一般使用JKS文件,如果有Pem和key文件,也需要合成JKS文件,并且JKS的密码尽量不要太复杂,一般为纯数字即可。
第二步:进入Tomcat安装目录,把证书的jks格式文件放在tomcat安装目录即可,在CONF目录创建一个名称为SSL的文件夹。
conf/ssl/tongpeifu.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.Http11NioProtocol"
maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
sslEnabledProtocols="TLSv1.2,TLSv1.1,TLSv1" clientAuth="false"
keystoreFile="conf/ssl/tongpeifu.jks" keystorePass="123456" />
其中代码中的443端口是默认的Https端口,也可以自定义端口, tongpeifu.jks 替换为您自己的证书文件,密码替换为您自己设定的密码。
第五步:重启Tomcat服务,然后即可生效。
如果需要在Tomcat6,7和8.0版本设置强制https跳转,方法如下:
其中代码中的443端口是默认的Https端口,也可以自定义端口, tongpeifu.jks 替换为您自己的证书文件,密码替换为您自己设定的密码。
第五步:重启Tomcat服务,然后即可生效。
如果需要在Tomcat6,7和8.0版本设置强制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://域名。