免費爲域名生成證書

  • 目的
    後臺需要https或者前端需要https訪問。需要有域名證書,介紹如何生成https證書。域名任意前綴都支持。本例子使用certbot簽發letsencrypt證書,讓spring boot後端使用。達到後端https的目的。
  • 資料
    https://letsencrypt.org/
    https://certbot.eff.org/lets-encrypt/ubuntubionic-nginx

1.安裝certbot

sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository universe
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update

sudo apt-get install certbot python3-certbot-nginx

2.ssl證書生成與域名增加TXT記錄

  • 2.1開始生成證書,把abc.com換成自己的域名
sudo certbot certonly  -d "*.abc.com" -d abc.com --manual --preferred-challenges dns-01  --server https://acme-v02.api.letsencrypt.org/directory
  • 2.2 執行上方語句會出現如下片段
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name
_acme-challenge.abc.com with the following value:

lSdsQvr1bsdfsffsdfwwfwefwewesfdfsdfss

Before continuing, verify the record is deployed.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  • 2.3 添加txt解析記錄呢。去域名購買商(如xx雲 - 域名管理)那裏,增加解析,然後選擇解析類型爲TXT即可。
    就是說,把 _acme-challenge.abc.com作爲名字,lSdsQvr1bsdfsffsdfwwfwefwewesfdfsdfss作爲值,添加txt解析記錄。

  • 2.4 查看最終文件結果

$ sudo ls .
README	cert.pem  chain.pem  fullchain.pem  privkey.pem

3.生成spring boot可用的PKCS12證書

openssl pkcs12 -export -in fullchain.pem -inkey privkey.pem -out  abc.p12

在spring boot 中使用,在配置文件application.properties中

###ssl
server.ssl.key-store:classpath:abc.p12
server.ssl.key-store-password:自己的密碼
server.ssl.keyStoreType:PKCS12

此時放到服務器後就是可用的https訪問了,並且域名也是txt了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章