acme.sh 搭配 GoDaddy 自動續期 Let's Encrypt 免費萬用憑證 - MIS 腳印
MIS 腳印 logo

MIS 腳印

記錄 IT 學習的軌跡

acme.sh 搭配 GoDaddy 自動續期 Let's Encrypt 免費萬用憑證

在 CentOS 7 使用 acme.sh 搭配 GoDaddy API Key 的方式,來自動續期 Let’s Encrypt 免費的萬 (通) 用字元憑證 SSL/TLS,完全不需手動執行任何操作。

Let's Encrypt

使用 Let’s Encrypt 萬用字元憑證 (Wildcard Certificates) 的方式,就不用針對每個子網域申請一個對應的憑證,即可通用於所有子網域的網站,對於像本站是建置 WordPress MU 多子網域的方式,使用起來就更方便了。

GoDaddy

使用 API Key 就能自動續期憑證, 無需手動執行任何操作。

新增 API Key

前往 GoDaddy 新增 API Key:

輸入自訂的 API Key 名稱,且必須選擇「Production」:

產生 API 的 Key 與 Secret,在後續的申請憑證需要用到:

acme.sh

安裝

使用 curl 安裝 (其它安裝方式可參考 GitHub - Neilpang/acme.sh)

curl https://get.acme.sh | sh
# ... 以上省略 ...

[二  3月  5 06:14:12 CST 2019] Good, bash is found, so change the shebang to use bash as preferred.
[二  3月  5 06:14:12 CST 2019] OK
[二  3月  5 06:14:12 CST 2019] Install success!

須重新登入:

logout

自動更新

由於 acme.sh 仍不斷在發展,因此建議讓它保持在最新的狀態。

手動更新到最新:

acme.sh --upgrade

啟用自動更新:

acme.sh --upgrade --auto-upgrade

禁用自動更新:

acme.sh --upgrade --auto-upgrade 0

申請憑證

將上述 GoDaddy 新增的 API Key 和 Secret 貼上並執行:

export GD_Key="xxxxxtpTEP3_xxxxxx9dn3Tdwv8PZxxxxx"
export GD_Secret="xxxxxtmxxxxxZwuWrxxxxx"

申請網域 (Domain) 的萬用憑證 (請替換 footmark.info 為要申請網域),成功後會顯示憑證存放的路徑:

acme.sh --issue --dns dns_gd -d footmark.info -d *.footmark.info
# ... 以上省略 ...

-----END CERTIFICATE-----
[二  3月  5 20:01:25 CST 2019] Your cert is in  /root/.acme.sh/footmark.info/footmark.info.cer
[二  3月  5 20:01:25 CST 2019] Your cert key is in  /root/.acme.sh/footmark.info/footmark.info.key
[二  3月  5 20:01:25 CST 2019] The intermediate CA cert is in  /root/.acme.sh/footmark.info/ca.cer
[二  3月  5 20:01:25 CST 2019] And the full chain certs is there:  /root/.acme.sh/footmark.info/fullchain.cer

安裝憑證

Nginx

新增一個保存憑證的自訂目錄 (使用網域做為目錄名稱會是不錯的方式):

mkdir /etc/nginx/ssl/footmark.info

將憑證複製到上述新增的目錄路徑 (請替換 footmark.info 為要申請的網域和 /etc/nginx/ssl/... 路徑),並強制重啟 Nginx:

[root@localhost ~]# acme.sh --install-cert -d footmark.info \
--key-file       /etc/nginx/ssl/footmark.info/key.pem \
--fullchain-file /etc/nginx/ssl/footmark.info/cert.pem \
--reloadcmd     "service nginx force-reload"
[二  3月  5 20:50:52 CST 2019] Installing key to:/etc/nginx/ssl/footmark.info/key.pem
[二  3月  5 20:50:52 CST 2019] Installing full chain to:/etc/nginx/ssl/footmark.info/cert.pem
[二  3月  5 20:50:52 CST 2019] Run reload cmd: service nginx force-reload
Redirecting to /bin/systemctl force-reload nginx.service
[二  3月  5 20:50:52 CST 2019] Reload success

停止自動續期憑證

從續期列表中移除憑證 (請替換 footmark.info 為要申請的網域):

acme.sh --remove -d footmark.info

參考

在〈acme.sh 搭配 GoDaddy 自動續期 Let's Encrypt 免費萬用憑證〉中有 10 則留言

    • 不需要,acme.sh 支援多家網域商使用 API Key 方式自動續期「萬用字元憑證」。
      acme.sh 也支援其它方式自動續期,只是我覺得 API Key 較方便省事,除非是不支援的網域商。

    • 您這錯誤我沒遇到過,Google search 不少人有發生此問題,可先嘗試查找原因。

  1. 我發現 acme.sh不會幫你更新憑證耶,但是看 crontab也是有自動執行 acme.sh, acme.sh 內定是 60天自動更新嗎?我每次都是過期,我已經爛過三四次了,每次都要重新 force renew,重新安裝新憑證,重新複製並更新於 VestaCP後台

    • 1.我有幾個網站使用 acme.sh 都會自動更新憑證,尚未遇到不會自動更新憑證的狀況。
      2.您在確認安裝憑證所有步驟都正確執行且無錯誤。

發表迴響