重庆小潘seo博客

当前位置:首页 > 重庆网络营销 > 小潘杂谈 >

小潘杂谈

如何在Tomcat中配置SSL证书

时间:2020-09-23 20:00:06 作者:重庆seo小潘 来源:
我们假设已经在系统中安装了Tomcat服务器。如果没有,可以在CentOS、Rhel或Ubuntu、Debian系统上安装Tomcat7。本篇文章既可用于Linux,也可用于Windows主机,我们唯一需要更改的是KeyStore的目录路径。 步骤1:创建密钥库 Java KeyStore(JKS)是安全证书的

我们假设已经在系统中安装了Tomcat服务器。如果没有,可以在CentOS、Rhel或Ubuntu、Debian系统上安装Tomcat7。本篇文章既可用于Linux,也可用于Windows主机,我们唯一需要更改的是KeyStore的目录路径。

如何在Tomcat中配置SSL证书

步骤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视频教程栏目!以上就是如何在Tomcat中配置SSL证书的详细内容,更多请关注小潘博客其它相关文章!