如何设置 letencrypt SSL 证书并在 Spring Boot 应用程序中使用它? [英] How can I set up a letsencrypt SSL certificate and use it in a Spring Boot application?

查看:49
本文介绍了如何设置 letencrypt SSL 证书并在 Spring Boot 应用程序中使用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是保护服务器的新手,所以我对此知之甚少,但我需要让在 Digital Ocean Droplet 上运行的 Spring Boot 应用程序使用 HTTPS.

I'm new to securing a server so I don't really know much about this but I need to get my Spring Boot Application that is running on a Digital Ocean Droplet to use HTTPS.

我的想法是注册一个 Letencrypt 证书,然后告诉 Spring 使用它.

My idea is to register a letsencrypt certificate and then tell Spring to use that.

但是,我不知道该怎么做.

However, I have no idea how to do that.

谢谢.

推荐答案

我写了 2 篇关于 Let's Encrypt 和 Spring Boot 的博文.

I wrote 2 blog posts about Let's Encrypt and Spring Boot.

  1. 颁发证书. 由 Let's Encrypt 证书保护的 Spring Boot 应用程序
  2. 更新证书.让我们加密证书更新:对于 Spring启动

简而言之,步骤如下:

  1. 拉取让我们加密客户端 (certbot).

  1. Pulling the Let's Encrypt client (certbot).

为您的域(例如 example.com)生成证书

Generating a certificate for your domain (e.g. example.com)

./certbot-auto certonly -a standalone -d example.com -d www.example.com

事物在 /etc/letsencrypt/live/example.com 中生成.Spring Boot 需要 PKCS#12 格式的文件.这意味着您必须将密钥转换为 PKCS#12 密钥库(例如使用 OpenSSL).如下:

Things are generated in /etc/letsencrypt/live/example.com. Spring Boot expects PKCS#12 formatted file. It means that you must convert the keys to a PKCS#12 keystore (e.g. using OpenSSL). As follows:

  1. 打开/etc/letsencrypt/live/example.com 目录.
  1. Open /etc/letsencrypt/live/example.com directory.
`openssl pkcs12 -export -in fullchain.pem -inkey privkey.pem -out keystore.p12 -name tomcat -CAfile chain.pem -caname root`

带有 PKCS12 的文件 keystore.p12 现在在 /etc/letsencrypt/live/example.com 中生成.

The file keystore.p12 with PKCS12 is now generated in /etc/letsencrypt/live/example.com.

是时候配置您的 Spring Boot 应用程序了.打开 application.properties 文件并将以下属性放在那里:

It's time to configure your Spring Boot application. Open the application.properties file and put following properties there:

server.port=8443
security.require-ssl=true
server.ssl.key-store=/etc/letsencrypt/live/example.com/keystore.p12
server.ssl.key-store-password=<your-password>
server.ssl.keyStoreType=PKCS12
server.ssl.keyAlias=tomcat

阅读我的博文了解更多详情和评论.

Read my blog post for further details and remarks.

这篇关于如何设置 letencrypt SSL 证书并在 Spring Boot 应用程序中使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆