公司网站链接要由原来的http超文本传输协议访问改为https SSl加密传输协议访问。
HTTP与HTTPS的区别:HTTP协议传输的数据都是未加密的,也就是明文的,因此使用HTTP协议传输隐私信息非常不安全,为了保证这些隐私数据能加密传输,于是网景公司设计了SSL(Secure Sockets Layer)协议用于对HTTP协议传输的数据进行加密,从而就诞生了HTTPS。简单来说,HTTPS协议是由SSL+HTTP协议构建的可进行加密传输、身份认证的网络协议,要比http协议安全。
我花了一块钱(一年)在爱名网购买了一个Symantec Basic DV 证书。下载证书解压之后是这个样子的:
打开IIS文件夹:
包含证书的密码和一个pfx格式的证书。我开始用pfx格式证书来配置一直没成功,就选择了把pfx格式转换成jks格式的证书来配置,成功了。这里就讲jks格式证书的配置。
一、使用java jdk将PFX格式证书转换为JKS格式证书
先切换到IIS文件夹下,执行命令:
1
|
keytool -importkeystore -srckeystorewww.dongnaoedu.com_ssl.pfx -destkeystoredomains.jks -srcstoretype PKCS12 -deststoretype JKS |
这里要输入密码,就是上面www.dongnaoedu.com_pfx_password.txt文本文件中的密码,3个口令最好都输入这个密码。可以看到文件夹中生成了domains.jks证书
二、配置server.xml
先把domains.jks证书上传到Tomcat的conf文件夹下:
切换到conf目录下编辑server.xml
- cd /usr/tomcat/apache-tomcat-8.5.11/conf
- vim server.xml
找到:
1
2
3
4
5
|
<!-- <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" maxThreads="150" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS"/> --> |
去掉注释,修改为:(443为https默认访问端口)
1
2
3
4
5
|
< Connector port = "443" protocol = "HTTP/1.1" SSLEnabled = "true" maxThreads = "150" scheme = "https" secure = "true" keystoreFile = "conf/domains.jks" //证书地址 keystorePass = "582629" //证书密钥 clientAuth = "false" sslProtocol = "TLS" /> |
为了让http访问自动跳转为https访问,这里顺便把这两个标签也改了,
找到:
1
2
3
4
5
|
< Connector port = "8080" protocol = "HTTP/1.1" connectionTimeout = "20000" redirectPort = "8443" /> |
修改为:
1
2
3
4
5
|
< Connector port = "8080" protocol = "HTTP/1.1" connectionTimeout = "20000" redirectPort = "443" /> |
找到:
1
|
< Connector port = "8009" enableLookups = "false" protocol = "AJP/1.3" redirectPort = "8443" /> |
修改为:
1
|
< Connector port = "8009" enableLookups = "false" protocol = "AJP/1.3" redirectPort = "443" /> |
保存退出。
三、配置web.xml
编辑web.xml
- vim web.xml
在该文件</welcome-file-list>标签(一般在文件最末尾)后面加上这样一段:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
< 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即可。证书生效,并且http访问会自动转为https访问。
到此这篇关于Tomcat配置https SSL证书的项目实践的文章就介绍到这了,更多相关Tomcat配置https SSL证书内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!
原文链接:https://blog.csdn.net/Axela30W/article/details/77145887