使用 acme.sh 搭配 Let's encrypt 申請 wildcard ssl 憑證

之前一直都是使用 certbot 套件
不過換到 CentOS 8 後
這個套件到今天(2020.05.28)為止還沒支援就是
由於 certbot 是用 pythlon 開發的
所以安裝時會安裝一堆相依的套件
這也是我一直不喜歡用 certbot 的原因
會間接搞亂我的環境

後來找到 acme.sh
是使用 shell script 撰寫的
相對來說單純很多
安裝也很簡單

這個範例是搭配 Cloudflare DNS 做設定

安裝 acme.sh

我是使用 root 執行安裝的
curl  https://get.acme.sh | sh
所以安裝完會出現 /root/.acme.sh 這個資料夾


取得 Cloudflare 的 key

登入你的 cloudflare 帳號後


點選下方「Global API Key」右邊的 View
認證完後會取得一組 Key


申請 SSL 憑證

在 /root/ 下新增一個 ssl_cert.sh 檔案
其中 yourdomain.tld 為你自己的網域名稱,如 google.com
因為有指定目錄於 /etc/letsencrypt 中
所以憑證應該會出現在 /etc/letsencrypt/yourdomain.tld 下

由於是 wildcard 的關係,所以會指定兩個 domain 分別為 yourdomian.tld 及 *.yourdomain.tld
請注意,務必讓 yourdomain.tld 在第一個,如果讓 *.yourdomain.tld 在前面的話,你的資料夾就會是 *.yourdomain.tld

export CF_Key="your global api key"
export CF_Email="你的 cloudflare 登入的帳號(信箱)"
/root/.acme.sh/acme.sh --issue -d yourdomain.tld -d *.yourdomain.tld --cert-home /etc/letsencrypt --keylength 2048 --dns dns_cf \
--reloadcmd "systemctl reload nginx"

編輯上述檔案後儲存離開後
直接執行以下指令即可

sh /root/ssl_cert.sh

單一申請單獨 SSL 憑證

如果你不想申請 wildcard SSL 憑證(跟上方則一使用就好)
可以透過這個方式申請
systemctl stop nginx;
acme.sh --issue --standalone -d www.yourdomain.tld --cert-home /etc/letsencrypt --keylength 2048;
systemctl start nginx

 注意,使用 standalone 參數需要暫時停止 nginx 服務


安裝環境

  • CentOS 8
  • Nginx 1.14.1

參考文件



Comments

Popular posts from this blog

CentOS7 如何新增/移除 Rich Rule for firewalld

mac 安裝 mtr

Howto use Postman test Cors