SSL For Free: 使用Let’s Encrypt 申請SSL憑證

01_ SSL For Free_ Let's Encrypt cover

當網站加入 SSL 加密協定(HTTPS,網址列會是綠色鎖頭圖示),就不會被讀者誤會是危險網站或詐騙網站了(HTTP,是紅色鎖頭圖示)。申請方式其實很簡單,但是因為是免費的,所以每3個月需要重新申請憑證。

用手機日曆功能提醒憑證到期日,或者注意線上申請網站發送的電子郵件通知信,通常會在憑證到期前一個星期會收到信件,然後再找個時間更新憑證就可以了!

Let’s Encrypt 是什麼?

從下圖可以清楚了解 Let’s Encrypt 是憑證中心,可以透過線上工具網站(Certbot)的幫忙,完成憑證申請,然後再安裝於網站當中。整個流程都是免費的,不需要額外付費。假使是免費申請的話,憑證效期只有 90 天,在期限到之前,必須再重新申請一次憑證來使用。

10_ Let's Encrypt ZeroSSL SSLforFree
申請憑證示意圖

使用 Certbot 申請免費的 SSL 憑證

下載 Certbot 工具

方法 1

前往官網尋找安裝軟體:https://certbot.eff.org/instructions?ws=apache&os=windows
適合對象:想了解更多 Certbot Instructions 內容

Certbot has discontinued support for Windows as of February 2024. You can find alternatives listed on our community announcement here

方法 2

直接下載 Certbot 2.9.0 Windows 安裝檔:https://github.com/certbot/certbot/releases/tag/v2.9.0
檔案名稱:certbot-beta-installer-win_amd64_signed.exe
執行程式後會安裝在 C:\Program Files\Certbot\ 目錄底下。
適合對象:直接進入申請憑證流程

確認 Certbot 是否有安裝成功

打開系統管理員身份執行開啟 Command Prompt,然後輸入以下指令:

Microsoft Windows [版本 10.0.26100.3476]
(c) Microsoft Corporation. 著作權所有,並保留一切權利。

C:\Windows\System32>cd C:\Program Files\Certbot\bin\

C:\Program Files\Certbot\bin>certbot --version
certbot 2.9.0

出現 certbot 2.9.0 表示安裝成功。

建立單一域名與萬用域名憑證

以我的 hipay0.com 網域名稱為範例,輸入以下命令同時產生
hipay0.com 網域憑證
*.hipay0.com 萬用子網域憑證。

C:\Program Files\Certbot>certbot certonly --manual -m YOUREMAIL@gmail.com -d hipay0.com -d *.hipay0.com

出現下列說明後,先不用急著按任意鍵!!!必須先前往 DNS provider 修改 DNS TXT record。

Please deploy a DNS TXT record under the name:
_acme-challenge.hipay0.com
with the following value:
18tsdddssss_DH1dddd
Before continuing, verify the TXT record has been deployed. Depending on the DNS
provider, this may take some time, from a few seconds to multiple minutes. You can
check if it has finished deploying with aid of online tools, such as the Google
Admin Toolbox: https://toolbox.googleapps.com/apps/dig/#TXT/_acme-challenge.hipay0.com
Look for one or more bolded line(s) below the line ‘;ANSWER’. It should show the
value(s) you’ve just added.
Press Enter to Continue

前往 DNS 服務商,新增一筆 TXT 紀錄到 _acme-challenge.hipay0.com 的域名上,並將其值設定為 Certbot 需要驗證的指定值。
Type:TXT
Name:_acme-challenge
TTL:Auto
Content:18tsdddssss_DH1dddd

更新完之後,前往 https://toolbox.googleapps.com/apps/dig/#TXT/_acme-challenge.hipay0.com 確認一下 Content 是否正確。沒問題後,可以按下任意鍵。

建立單一域名憑證

…\htdocs\ 目錄下新增 .well-known 資料夾

指令:
mkdir .well-known

.well-known 資料夾底下新增 acme-challenge 資料夾

路徑:
...\htdocs\.well-known\acme-challenge

打開系統管理員身份執行開啟 Command Prompt,然後輸入以下指令:

指令:
C:\Program Files\Certbot>certbot certonly --manual -m YOUREMAIL@gmail.com -d hipay0.com

出現以下說明按下 Y

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

出現以下說明按下 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

在路徑:…\htdocs\.well-known\acme-challenge\
新增一個沒有副檔名的檔案:
檔名是:81ffffggggg
檔案內容是:81ffffggggg.2iFsssssssse0
注意事項:檔名檔案內容要根據提示進行修改

Account registered.
Requesting a certificate for hipay0.com
Create a file containing just this data:
81ffffggggg
And make it available on your web server at this URL:
https://hipay0.com/.well-known/acme-challenge/81ffffggggg
Press Enter to Continue

在瀏覽器輸入一下連結,確認是否可以正常連線:
https://hipay0.com/.well-known/acme-challenge/81ffffggggg

確定瀏覽器可以開啟 https://hipay0.com/.well-known/acme-challenge/81ffffggggg 後,在【命令提示字元】視窗中,按下【Enter】發出憑證請求,開始申請憑證。

Successfully received certificate.
Certificate is saved at: C:\Certbot\live\hipay0.com\fullchain.pem
Key is saved at: C:\Certbot\live\hipay0.com\privkey.pem
This certificate expires on 2025-07-02.
These files will be updated when the certificate renews.

NEXT STEPS:
This certificate will not be renewed automatically. Autorenewal of –manual certificates requires the use of an authentication hook script (–manual-auth-hook) but one was not provided. To renew this certificate, repeat this same certbot command before the certificate’s expiry date.

If you like Certbot, please consider supporting our work by:
Donating to EFF: https://eff.org/donate-le
Donating to ISRG / Let’s Encrypt: https://letsencrypt.org/donate

單一域名憑證 4 個檔案存放在:C:\Certbot\archive\hipay0.com\
cert1.pem
chain1.pem
fullchain1.pem
privkey1.pem

certbot 指令說明

1. certonly:只產生憑證,讓 Certbot 不要自動產生或修改網頁伺服器的設定檔案
2. certbot certonly:半自動驗證(自備 HTTP 伺服器,不調整網頁伺服器設定)
3. –server:指定 CA server。Certbot 預設的 Let’s Encrypt’s production server 是 https://acme-v02.api.letsencrypt.org/directory。(來源資料:Changing the ACME Server)
4. –manual:使用手動驗證
5. –preferred-challenges dns:使用 DNS 的方式完成驗證 challenge
6. -d:指定網域名稱,例如:hipay0.com
7. –dry-run:測試用途,一旦驗證流程完全正確後,務必把這個參數刪除再重新執行一次。因為 Certbot 規定,同一網域驗證過程失敗 5 次後,會封鎖用戶繼續使用 Certbot。需要等待 1 小時後,才會開放用戶繼續使用 Certbot。(來源資料:Rate Limits – Let’s Encrypt)

哪種憑證申請方式適合我?

申請 Let’s Encrypt 免費憑證,只需要選擇以下一種認證流程就好了。
建立單一域名與萬用域名憑證:hipay0.com 與 *.hipay0.com
建立單一域名憑證:hipay0.com

單一域名憑證存放路徑

當憑證已經建立完成後,把憑證放在 …\Apache24\conf\ 的資料夾裡面。
…\Apache24\conf\ssl.crt\ 的資料夾存放:
cert1.pem
chain1.pem
fullchain1.pem

…\Apache24\conf\ssl.key\ 的資料夾存放:
privkey1.pem

修改 httpd-ssl.conf

打開設定檔檔案:
將 Line 149 改成: SSLCertificateFile “${SRVROOT}/conf/ssl.crt/cert1.pem”
將 Line 172 改成: SSLCertificateChainFile “${SRVROOT}/conf/ssl.crt/chain1.pem”
將 Line 180 改成: SSLCACertificateFile “${SRVROOT}/conf/ssl.crt/fullchain1.pem”
將 Line 159 改成: SSLCertificateKeyFile “${SRVROOT}/conf/ssl.key/privkey1.pem”

清除快取,重開 Apache,打開網站假使有看到綠色鎖頭,就表示全部流程都完成了。

在 Windows 作業系統自己架設網站教學

只要照著我的步驟做,相信你也可以不用額外花半毛錢,就可以在 Windows 作業系統上面,架設好屬於自己的專屬網站了(這篇文章可以看到自架網站的完整敘述)。而這系列的分享文章,是寫給架站新手 / 小公司 / 部落客的,不適用於大型企業 / 大神級…

架站硬體

防火牆

free desktop pc svgrepo com
click svgrepo com

防火牆

firewall svgrepo com
click svgrepo com

架站工具

架站懶人包

xampp svgrepo com
click svgrepo com

獨立安裝架站軟體

xampp svgrepo com
click svgrepo com

獨立安裝架站軟體

安裝Apache、MySQL、phpMyAdmin

SSL 憑證

certificate ssl svgrepo com
click svgrepo com

商標設計

logo apple ar svgrepo com
click svgrepo com

申請網域

domain www svgrepo com
click svgrepo com

架站效能

網站設定

setting line svgrepo com 1
click svgrepo com

網站設定

軟體參數微調

快取外掛

shower svgrepo com
click svgrepo com

架站安全

網頁標題

quiz title svgrepo com
click svgrepo com

廣告違規

advertisement svgrepo com
click svgrepo com

常見問題

為什麼免費版憑證只有 90 天的有效期限呢?

跟密鑰洩露和誤發行有關係,假使發生錯誤或被盜的話,可以在較短的時間內發現、解決。

常見的憑證申請網站有哪些?

幾個常見的網站都提供憑證申請:
1. Let’s Encrypt: https://letsencrypt.org/
2. Certbot: https://certbot.eff.org/
3. Free S S L Certificate: https://www.freesslcertificate.org/

免費版憑證,只能考慮使用 Let’s Encrypt 嗎?

可以有其它選擇,例如: The better option is provided by Cloudflare.
Cloudflare 不僅只是 CDN service provider,也提供免費版的憑證讓 CDN 用戶使用。

進行 HTTP 連線驗證失敗怎麼辦?

路由器或防火牆開放 Port 80 讓 Let’s Encrypt 進行 HTTP 連線存取網址。

強烈建議使用 Certbot 申請 Let’s Encrypt 免費 SSL 憑證

想要完全免費使用憑證的話,建議採取【Certbot】的方式,才能不限次數使用免費的憑證。或許您也可以使用第三方服務 Qualys Labs 提供的檢查程式來檢測網站的 HTTPS 配置和評分級別。