用certbot申請Let's Encrypt泛域名證書

什麼是Let's Encrypt?

目前世界上就只有爲數不多的幾家域名證書籤發機構得到瀏覽器的認可,而Let‘s Encrypt

就是其中一家,並且你可以申請到免費的證書,當然你如果想要付費也行,很多機構證書動輒幾千幾萬一年。如果我們只想搭建個測試環境有需要https,我們肯定不會去花這個冤枉錢,當然免費的午餐並沒有那麼好喫,Let's Encrypt申請的證書只有90天有效期,所以到期你得進行續期操作。並且還有各種各樣得條件限制,比如一週你只能申請多少次,同一個ip一天只能操作多少次之類,詳見

https://letsencrypt.org/docs/rate-limits/

假如你使用jdk生成的自簽證書能不能用呢?當然是可以用的,只不過瀏覽器會告訴你這個證書我不承認。也就是左上角會給你掛個不安全的警告。

什麼是泛域名證書?

例如:*.xxx.cn 也就是這個證書可以給某個域名的所有二級域名使用,就叫做泛域名證書(也稱作通配符證書)。

Let's Encrypt 官方推薦我們使用certbot 腳本申請證書(當然也可以使用acme.sh等方式),以下是申請步驟基於Debian10 python3.7.3如果你在操作過程中遇到什麼報錯,請多考慮python工具包的版本問題之類的。

Let's Encrypt自2018年開始支持申請泛域名證書,相比於單域名證書,泛域名證書更利於日常的維護。

準備工作

下載 certbot,這個很多發行版的源中都已經自帶了。比如Debian的:

sudo apt install certbot

需要有域名的管理權限,因爲申請泛解析證書需要使用 DNS 驗證,這就需要你能夠根據要求操作 DNS 解析記錄,以此證明你對域名的權限。

開始申請泛域名證書

certbot certonly --preferred-challenges dns --manual  -d *.xx.cn --server https://acme-v02.api.letsencrypt.org/directory

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator manual, Installer None
Obtaining a new certificate
Performing the following challenges:
dns-01 challenge for xx.cn


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NOTE: The IP of this machine will be publicly logged as having requested this
certificate. If you're running certbot in manual mode on a machine that is not
your server, please ensure you're okay with that.


Are you OK with your IP being logged?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: y


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name
_acme-challenge.xx.cn with the following value:


nI0DhzH-vn0W7STVuLi2O-oIKuFNlqQx5EnjB-zewvs


Before continuing, verify the record is deployed.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue   #讓你的二級域名_acme-challenge.xx.cn用TXT方式解析到nI0DhzH-vn0W7STVuLi2O-oIKuFNlqQx5EnjB-zewvs

#可用dig -t txt _acme-challenge.xx.cn驗證解析是否生效,然後按下Enter通過驗證。 debian可用apt install dnsutils來安裝dig命令。

Waiting for verification...
Cleaning up challenges


IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/xx.cn/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/xx.cn/privkey.pem
Your cert will expire on 2021-04-26. To obtain a new or tweaked
version of this certificate in the future, simply run certbot
again. To non-interactively renew *all* of your certificates, run
"certbot renew"
- If you like Certbot, please consider supporting our work by:


Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le

#至此證書申請成功

參數說明:

certonly 表示只申請證書。

--no-bootstrap 需要用戶同意的系統級操作直接選N。

--manual 表示交互式申請。

-d 爲那些主機申請證書如 *.xxx.cn(此處爲泛域名)

--preferred-challenges dns,使用 DNS 方式校驗域名所有權,可以配置多個

--server Let's Encrypt ACME v2 版本使用的服務器不同於 v1 版本(V2版本才支持泛域名解析),需要顯示指定。

證書籤發成功後去Nginx或Apache配置新生成的證書文件即可。

撤銷證書

倘若有不需要的證書了,可撤銷刪除。

sudo certbot revoke --cert-path /etc/letsencrypt/archive/xx.cn/cert1.pem

Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you like to delete the cert(s) you just revoked, along with all earlier
and later versions of the cert?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es (recommended)/(N)o: y #是否刪除證書

 

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