PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

如何在Tomcat中配置SSL证书

不言
不言 原创
2019-03-23 14:48:19 4026浏览

我们假设已经在系统中安装了tomcat服务器。如果没有,可以在centos、rhel或ubuntu、debian系统上安装tomcat7。本篇文章既可用于linux,也可用于windows主机,我们唯一需要更改的是keystore的目录路径。

步骤1:创建密钥库

Java KeyStore(JKS)是安全证书的存储库。keytool是用于创建和管理密钥库的命令行实用程序。JDK和JRE都可以使用此命令。我们只需要确保JDK或JRE配置了PATH环境变量。

$ keytool -genkey -aliassvr1.tecadmin.net-keyalg RSA -keystore/etc/pki/keystore

输出:

Enter keystore password:
Re-enter new password:
What is your first and last name?
  [Unknown]:Rahul KumarWhat is the name of your organizational unit?
  [Unknown]:WebWhat is the name of your organization?
  [Unknown]:TecAdmin Inc.What is the name of your City or Locality?
  [Unknown]:DelhiWhat is the name of your State or Province?
  [Unknown]:DelhiWhat is the two-letter country code for this unit?
  [Unknown]:INIs CN=Rahul Kumar, OU=Web, O=TecAdmin Inc., L=Delhi, ST=Delhi, C=IN correct?
  [no]:yesEnter key password for(RETURN if same as keystore password):
Re-enter new password:

步骤2:获取CA签名的SSL[忽略自签名用户]

如果要使用自签名SSL证书,则无需执行此步骤。如果要从证书颁发机构购买有效的ssl,则需要先创建CSR,使用以下命令执行此操作。

创建CSR:

$ keytool -certreq -keyalg RSA -alias svr1.tecadmin.net -file svr1.csr -keystore /etc/pki/keystore

上面的命令将提示输入密钥库密码并生成CSR文件。使用此CSR并从任一证书颁发机构购买ssl证书。

CA颁发证书后,将拥有以下文件: root certificate,intermediate certificate 和Issued certificate by CA。在此例中,文件名是

A. root.crt (root certificate)

B. intermediate.crt (intermediate certificate)

C. svr1.tecadmin.net.crt ( Issued certificate by CA )

安装root certificate:

$ keytool -import -alias root -keystore/etc/pki/keystore-trustcacerts -fileroot.crt

安装intermediate certificate:

$ keytool -import -alias intermed -keystore/etc/pki/keystore-trustcacerts -fileintermediate.crt

安装Issued certificate by CA

$ keytool -import -aliassvr1.tecadmin.net-keystore/etc/pki/keystore-trustcacerts -filesvr1.tecadmin.net.crt

步骤3:设置Tomcat密钥库

现在,转到你的Tomcat安装目录并在你喜欢的编辑器中编辑conf/server.xml文件,并按如下所示更新配置。如果需要,也可以将端口从8443更改为其他端口。

<Connector port="8443" protocol="HTTP/1.1"
                connectionTimeout="20000"
                redirectPort="8443"
                SSLEnabled="true"
                scheme="https"
                secure="true"
                sslProtocol="TLS"
                keystoreFile="/etc/pki/keystore"
                keystorePass="_password_" />

步骤4:重新启动Tomcat

使用init脚本(如果有)重新启动Tomcat服务,在这个例子中,我们使用的是shell脚本(startup.sh和shutdown.sh)来停止和启动Tomcat。

$ ./bin/shutdown.sh
$ ./bin/startup.sh

步骤5:验证安装程序

因为我们已经完成了Tomcat设置所需的所有配置。就可以在步骤2中的配置端口上访问浏览器中的Tomcat。

本篇文章到这里就已经全部结束了,更多其他精彩内容可以关注PHP中文网的Java视频教程栏目!

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。