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

給你的網站添加免費的Let’s Encrypt SSL 證書

admin
2025年8月14日 21:1 本文熱度 263

導讀:你將擁有一個不過期的SSL DV 免費證書,請看本文。

背景

之前網站使用的是免費證書,但是免費證書(默認證書)的簽發有效期由12個月縮短至3個月,很快就到期,這是要讓大多數企業購買付費證書的節奏啊,所以我更換了證書的簽發機構。本文主要講的就是如何使用 Let’s Encrypt的證書讓自己的網站免費從HTTP升級為HTTPS。 

目前比較流行的免費 SSL 證書有 Let’s encrypt 和 Cloudflare。這次我們先嘗試一下 Let’s encrypt。

Let's Encrypt 是一個由非營利性組織 互聯網安全研究小組(ISRG)提供的免費、自動化和開放的證書頒發機構(CA)。

Let's Encrypt 簡介

簡單的說,借助 Let's Encrypt 頒發的證書可以為我們的網站免費啟用 HTTPS(SSL/TLS) 。Let’s encrypt 證書是 DV(Domain Validation)證書,只驗證域名所有權,不驗證公司信息。

其證書的簽發/續簽都是腳本自動化的,官方提供了幾種證書的申請方式方法,網址為 https://letsencrypt.org/zh-cn/docs/client-options/。

安裝Certbot客戶端

[root@aliyun-www ~]# yum install certbot -y

等待它下載安裝完畢,檢測是否成功。使用如下命令:

[root@aliyun-www ~]# certbot --versioncertbot 2.11.0

現在已經安裝成功,接著就可以申請SSL證書了。

比如我們要為static.example.com申請證書(你可以更換為真實的域名),使用如下命令:

[root@aliyun-www ~]# certbot certonly --nginx -d static.example.com
Saving debug log to /var/log/letsencrypt/letsencrypt.log
The requested nginx plugin does not appear to be installed
Ask for help or search for solutions at https://community.letsencrypt.org. See the logfile /var/log/letsencrypt/letsencrypt.log or re-run Certbot with -v for more details.

執行時,如果出現上面的提示,需要 nginx plugin 插件,可以運行如下命令,安裝相應的插件解決:

[root@aliyun-www ~]# yum install python3-certbot-nginx

接著,請讓我們再次運行申請SSL的指令:

[root@aliyun-www ~]# certbot certonly --nginx -d static.example.com

接下來,是一個交互的過程。

是否同意 Let's Encrypt 協議要求=>需要同意,是否分享你的郵箱,詢問是否對域名和機器(IP)進行綁定=>需要同意。

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Enter email address (used for urgent renewal and security notices)
(Enter 'c' to cancel): youname@example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.5-February-24-2025.pdf. You must
agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: y
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, to
share your email address with the Electronic Frontier Foundation, a founding
partner of the Let's Encrypt project and the non-profit organization that
develops Certbot? We'd like to send you email about our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: y
Account registered.
Requesting a certificate for static.example.com
Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/static.example.com/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/static.example.com/privkey.pem
This certificate expires on 2025-06-18.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

證書生成完畢后,我們可以在 /etc/letsencrypt/live/ 目錄下看到對應域名的文件夾,里面存放了指向證書的一些快捷方式。

證書續簽:自動更新 SSL 證書

Let’s Encrypt 提供的證書只有90天的有效期,證書在到期前30天才會續簽成功,我們必須在證書到期之前,重新獲取這些證書,certbot 給我們提供了一個很方便的命令,那就是 certbot renew。通過這個命令,他會自動檢查系統內的證書,并且自動更新這些證書。可以運行這個命令測試一下:

[root@aliyun-www ~]# certbot renew --dry-run

Certbot 會檢查證書是否過期,如果過期會自動續期。可以將 certbot renew 添加到Cron定時任務,定期檢查證書是否過期。

Nginx 開啟 https

證書生成完成后可以到 /etc/letsencrypt/live/ 目錄下查看對應域名的證書文件。編輯 nginx 配置文件監聽 443 端口,啟用 SSL,并配置 SSL 的公鑰、私鑰證書路徑:

server {
  listen   443 ssl;
  server_name  example.cn;
  root /home/www/example.com;
  index  index.html index.htm index.php;
   ssl_certificate /etc/letsencrypt/live/example/fullchain.pem;
   ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
   ...
}

添加 HTTP 自動跳轉到 HTTPS:

server {
   listen 80;
   server_name example.com;
   location / {
       rewrite ^(.*)$  https://$host$1 permanent;
   }
}

配置好Nginx后,重新啟動:

systemctl restart nginx

這樣,你就可以一直有不過期的證書了。

結語

通過執行這些步驟,我們已在 CentOS 9 服務器上成功安裝和配置 Let's Encrypt SSL,從而為網站訪問者提供安全通信。請定期檢查你的配置和更新,以維護安全可靠的網絡狀態。

作者:場長

閱讀原文:原文鏈接


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

黄频国产免费高清视频,久久不卡精品中文字幕一区,激情五月天AV电影在线观看,欧美国产韩国日本一区二区
亚洲中出在线视频 | 中文字幕在线视频网视频 | 亚洲精品成Av人在线免播放观看 | 在线亚洲欧美日韩中文字幕一区 | 亚洲日韩最大AV网站 | 日本有码中文字幕在线电影 |