1. 创建证书
第一步:为服务器生成证书
使用keytool 为 Tomcat 生成证书,假定目标机器的域名是“ localhost ”, keystore 文件存放在“ d:\tomcat.keystore ”,口令为“ password123 ”,使用如下命令生成:
keytool -genkey -v -alias tomcat -keyalg RSA -validity 3650 -keystore d:\tomcat.keystore -dname "CN=localhost,OU=cn,O=cn,L=cn,ST=cn,c=cn" -storepass password123 -keypass password123
Keystore放的是证书
创建私钥.cer文件。
keytool -export -alias tomcat -keystore d:\tomcat.keystore -file d:\tomcat.cer -storepass password123
2. 创建springboot项目
2.1. 拷贝证书到resources

2.2. Application.yml
server:
# 服务器的HTTP端口,默认为8080
port: 8080
ssl:
#文件所在位置
key-store: classpath:tomcat.keystore
#keystore的密码
key-store-password: password123
key-store-type: JKS
key-alias: tomcat
2.3. pom.xml
build中增加以下内容
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>*.keystore</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>*.keystore</include>
</includes>
</resource>
</resources>
2.4. 添加网页

2.5. 访问
2.5.1. 端口号8080
https://localhost:8080/index.html

2.5.2. 端口号改成443
https://localhost/index.html
3. 验证用户身份
用手机号发验证码
博客介绍了在Spring Boot项目中配置HTTPS的步骤,包括使用keytool为Tomcat生成证书、创建私钥文件,将证书拷贝到resources目录,配置Application.yml和pom.xml,添加网页并分别通过8080和443端口访问。此外,还提及使用手机号发验证码来验证用户身份。
2410

被折叠的 条评论
为什么被折叠?



