LOGO OA教程 ERP教程 模切知識交流 PMS教程 CRM教程 開發文檔 其他文檔  
 
網站管理員

手把手教你申請 Let''s Encrypt 免費 SSL 證書:從手動驗證開始!

admin
2025年8月14日 21:6 本文熱度 1007

前言

在如今的互聯網環境中,為網站配置 SSL 證書已成為安全的標配。本文使用?Let’s Encrypt?免費獲取泛域名 SSL 證書,采用?certbot + DNS-01?的手動方式獲取通配符證書,后續將推出自動續期篇,歡迎關注!

?? 什么是 Let’s Encrypt?

Let’s Encrypt?是一個免費的、自動化的、開放的證書頒發機構(CA),提供免費 SSL 證書。它的目標是讓所有網站都能輕松實現 HTTPS 加密,保障用戶數據的安全。通過?Let’s Encrypt,你可以為你的主域名、子域名,甚至泛域名配置安全證書,而且過程完全自動化,不需要手動申請和管理證書,官方推薦使用?Certbot

?? 什么是 Certbot?

Certbot?是一款免費的開源軟件工具,用于自動使用?Let’s Encrypt?證書在手動管理的網站上啟用?HTTPS

Certbot?是由電子前沿基金會 (EFF) 開發提供的免費工具,配合?Let's Encrypt,可以輕松為你的域名申請免費?SSL?證書。

?準備工作

? 一臺可以訪問互聯網的?Linux?服務器(CentOS / Ubuntu)
? 已解析并可控制 DNS 的域名(例如:example.com) ? 安裝好?certbot

安裝 Certbot 示例(CentOS):

yum install epel-release -y
yum install certbot -y

申請普通證書

如果只需要為特定域名申請證書(以?yourdomain.com?和?www.yourdomain.com為例):

certbot certonly --manual --preferred-challenges=dns-01 \
? --server https://acme-v02.api.letsencrypt.org/directory \
? --agree-tos -m your-email@example.com \
? -d yourdomain.com -d www.yourdomain.com

申請通配符證書(推薦)

如果希望一個證書覆蓋所有子域名,可以申請通配符證書, 使用下面這條命令申請通配符證書(以?*.example.comexample.com?為例):

certbot certonly --manual --preferred-challenges=dns-01 \
? --server https://acme-v02.api.letsencrypt.org/directory \
? --agree-tos -m your-email@example.com \
? -d?'*.example.com'?-d example.com

?? ??命令詳解:

  • --manual:使用手動交互模式獲取證書,不依賴 Web 服務或 DNS 插件
  • --preferred-challenges=dns-01:指定dns方式驗證,使用 DNS TXT 記錄進行驗證
  • --server https://acme-v02.api.letsencrypt.org/directory:指定驗證的服務端API Endpoint(對于當前版本的certbot這個url已經是默認值)。
  • -d:填寫你要申請的域名(支持多個)
  • 測試模式:可以添加--dry-run參數測試申請過程

輸入Yes后,即可開始DNS-01的驗證過程了。

??? 手動到域名服務商添加 DNS TXT 驗證記錄

certbot交互程序會指示我們所需添加的DNS TXT記錄,其中包括記錄名(_acme-challenge) 和記錄值(一個隨機生成的字符串):

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

qr4m0k3wYuGc5f8yYJhqanY-fUhlw546OSuxBEZYF70

Before continuing, verify the record is deployed.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
主機記錄:_acme-challenge.example.com
記錄值:qr4m0k3wYuGc5f8yYJhqanY-fUhlw546OSuxBEZYF70

添加到 DNS 服務商控制臺(如阿里云、騰訊云、Cloudflare)中:

主機記錄
類型
_acme-challenge.example.com
TXT
qr4m0k3wYuGc5f8yYJhqanY-fUhlw546OSuxBEZYF70

開一個新窗口使用?dig?命令檢查是否生效(生效后第一個窗口再回車):

dig _acme-challenge.example.com TXT

? 完成申請

當使用 Certbot 成功申請到 SSL 證書后,證書文件將默認保存在以下目錄中:

/etc/letsencrypt/live/example.com/

/etc/letsencrypt/live/example.com/cert.pem
/etc/letsencrypt/live/example.com/chain.pem
/etc/letsencrypt/live/example.com/fullchain.pem
/etc/letsencrypt/live/example.com/privkey.pem
/etc/letsencrypt/live/example.com/README

具體包含以下幾個文件:

  • cert.pem:這是你的?SSL 證書?文件。
  • privkey.pem:這是你的?私鑰?文件,務必妥善保管,切勿泄露。
  • chain.pem:這是?中間證書鏈?文件,用于驗證證書的完整性。
  • fullchain.pem:這是?完整證書鏈?文件,通常用于?Nginx?或?Apache?的 SSL 配置中。

?? 如何配置證書?

以 Nginx 為例:

提示:為了避免證書路徑錯誤,建議在 Nginx 或 Apache 配置中直接使用?fullchain.pem?和?privkey.pem?兩個文件。

ssl_certificate ? ? /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

保存并測試重載 Nginx 配置:

nginx -t
nginx -s reload

使用?certbot?查看證書信息

?? 查看所有已簽發證書信息

certbot certificates

輸出示例:

Saving debug?log?to /var/log/letsencrypt/letsencrypt.log
Cannot extract OCSP URI from /etc/letsencrypt/live/example.com/cert.pem

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Found the following certs:
? Certificate Name: example.com
? ? Serial Number: 5a4c055a0176abaf3579e87f81e1270826d
? ? Key Type: RSA
? ? Domains: *.example.com example.com
? ? Expiry Date: 2025-10-16 06:09:46+00:00 (VALID: 89 days)
? ? Certificate Path: /etc/letsencrypt/live/example.com/fullchain.pem
? ? Private Key Path: /etc/letsencrypt/live/example.com/privkey.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

?? 查看指定證書的詳細信息(以?example.com?為例)

openssl x509 -in?/etc/letsencrypt/live/example.com/cert.pem -text -noout

?? 查看證書包含哪些域名(SAN)

openssl x509 -in?/etc/letsencrypt/live/example.com/cert.pem -text -noout | grep -A 1?"Subject Alternative Name"

輸出示例:

X509v3 Subject Alternative Name:?
? ? DNS:*.example.com, DNS:example.com

?? 查看證書有效期

  • ? 只看過期時間(到期日期)
openssl x509 -enddate -noout -in?/etc/letsencrypt/live/example.com/cert.pem

輸出示例:

notAfter=Oct 16 06:09:46 2025 GMT
  • ? 同時查看起始和過期時間
openssl x509 -startdate -enddate -noout -in?/etc/letsencrypt/live/example.com/cert.pem

輸出示例:

notBefore=Jul 18 06:09:47 2025 GMT
notAfter=Oct 16 06:09:46 2025 GMT

?? 查看公鑰摘要(用于比對)

openssl x509 -in?/etc/letsencrypt/live/example.com/cert.pem -noout -modulus | openssl md5

??? 查看簽發機構(CA信息)

openssl x509 -in?/etc/letsencrypt/live/example.com/cert.pem -noout -issuer

?? 查看使用者(證書屬于誰)

openssl x509 -in?/etc/letsencrypt/live/example.com/cert.pem -noout -subject

?? 查看私鑰是否匹配證書

判斷 privkey.pem 是否與 cert.pem 一致(MD5摘要比對):

openssl rsa -noout -modulus -in?/etc/letsencrypt/live/example.com/privkey.pem | openssl md5

openssl x509 -noout -modulus -in?/etc/letsencrypt/live/example.com/cert.pem | openssl md5

? 兩個輸出一致則說明匹配。

??? 通過瀏覽器或遠程查看服務器證書

echo?| openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -dates -subject -issuer -text

常見問題

?? 證書有效期多久?

默認有效期是?90 天,需要定期續期。

DNS記錄多久生效?

通常幾分鐘到幾小時不等,具體取決于DNS服務商。

可以為多個域名申請一個證書嗎?

可以,使用多個-d參數即可。


?? 總結

? ? ? ? 通過本文你已經學會了如何使用?Certbot?工具手動申請免費 SSL 證書 ?,申請SSL證書是一個相對簡單的過程,特別是使用DNS驗證方式。雖然需要手動添加DNS記錄,但這種方式靈活性更高,適合各種部署場景。


閱讀原文:原文鏈接


該文章在 2025/8/15 11:37:53 編輯過
關鍵字查詢
相關文章
正在查詢...
點晴ERP是一款針對中小制造業的專業生產管理軟件系統,系統成熟度和易用性得到了國內大量中小企業的青睞。
點晴PMS碼頭管理系統主要針對港口碼頭集裝箱與散貨日常運作、調度、堆場、車隊、財務費用、相關報表等業務管理,結合碼頭的業務特點,圍繞調度、堆場作業而開發的。集技術的先進性、管理的有效性于一體,是物流碼頭及其他港口類企業的高效ERP管理信息系統。
點晴WMS倉儲管理系統提供了貨物產品管理,銷售管理,采購管理,倉儲管理,倉庫管理,保質期管理,貨位管理,庫位管理,生產管理,WMS管理系統,標簽打印,條形碼,二維碼管理,批號管理軟件。
點晴免費OA是一款軟件和通用服務都免費,不限功能、不限時間、不限用戶的免費OA協同辦公管理系統。
Copyright 2010-2025 ClickSun All Rights Reserved

黄频国产免费高清视频,久久不卡精品中文字幕一区,激情五月天AV电影在线观看,欧美国产韩国日本一区二区
日本一道久高清免费的视频 | 午夜美女福利视频 | 亚洲欧美日韩高清在线播放 | 亚洲中文字幕夜夜精品 | 一区二区三区四少妇 | 亚洲中文字幕第一页在线 |