acme获取https证书并配置到spingboot项目(standalone模式)

步骤

  1. Linux终端执行命令:curl https://get.acme.sh | sh
  2. 在当前用户目录下会生成.acme.sh目录,进入该目录
  3. 关闭nginx服务,因为下一步要监听80端口,而nginx会占用
  4. 执行命令:./acme.sh --issue -d xxx.com --standalone
    • 如果出现权限问题,就用root用户。如果用root用户,之后产生的证书相关文件可能会跑到root目录下,只需要把它们移动过来就行
  5. 会生成一个xxx.com目录,进入该目录(此时可以重新启动nginx了)
  6. openssl安装, 执行命令:yum -y install openssl
  7. 生成 p12 文件, 执行命令:openssl pkcs12 -export -in fullchain.cer -inkey xxx.com.key -out xxx.com.p12
  8. 根据 p12 文件生成 keystore 文件,执行命令:keytool -importkeystore -v -srckeystore xxx.com.p12 -srcstoretype pkcs12 -srcstorepass 123456 -destkeystore xxx.com.keystore -deststoretype jks -deststorepass 123456
  9. 生成OK,但是有条警告信息,把里面的建议命名复制出来执行一遍就好
  10. 然后又有一条警告,这条警告不用管,只是提示信息,提示把原来的证书文件备份为了 .old 文件
  11. 然后将keystore文件配置到项目的resource目录下就可以了
  12. 并在springboot配置文件中加入如下配置:
server:
  port: 8080
  ssl:
    enabled: true
    # keystore 文件
    key-store: classpath:ssl/xxx.com.keystore
    key-store-type: PKCS12
    # keystore的密码
    key-store-password: xxxxxx

参考:https://app.yinxiang.com/Home.action#n=689dd24a-98d8-4eb5-ad7c-8c999e20ff05&s=s25&ses=4&sh=2&sds=5&

ps:证书3个月到期,需手动更新
参考:
https://github.com/acmesh-official/acme.sh/wiki/How-to-issue-a-cert
https://springboot.io/t/topic/63

如何手动更新证书?

  • 就是重复上面的步骤,只是不用执行第一步了

2021-7-2 更新

  • 最近更新证书时提示:
[Fri Jul  2 16:24:51 CST 2021] Create account key ok.
[Fri Jul  2 16:24:51 CST 2021] No EAB credentials found for ZeroSSL, let's get one
[Fri Jul  2 16:24:51 CST 2021] acme.sh is using ZeroSSL as default CA now.
[Fri Jul  2 16:24:51 CST 2021] Please update your account with an email address first.
[Fri Jul  2 16:24:51 CST 2021] acme.sh --register-account -m [email protected]
[Fri Jul  2 16:24:51 CST 2021] See: https://github.com/acmesh-official/acme.sh/wiki/ZeroSSL.com-CA
[Fri Jul  2 16:24:51 CST 2021] Please check log file for more details: /home/mslin/.acme.sh/acme.sh.log
acme.sh  --register-account  -m [email protected] --server zerossl
  • 然后再更新证书就可以了
  • 如果nginx配置了证书的,还需要重启一下nginx

猜你喜欢

转载自blog.csdn.net/rakish_wind/article/details/115840424