EasyEngine 申請 Lets Encrypt 的 SSL 憑證

Share

  • Add this entry to Hatena Bookmark

使用 EasyEngine 申請 Lets Encrypt 的 SSL 憑證是件很簡單的事,而不需要在 VPS 主機上再安裝 epel-release 及 certbot 工具程序,幾個指令就可以完成。在申請 Lets Encrypt 的 SSL 憑證前,有一項重要的工作要先準備好,不然後面在申請證書的過程會出錯。就是先到 DNS 將你的頂級域名或是二級域名,都要有 www A 紀錄或別名都指到同一個 IP。

例如:

abc.example.com 二級域名,也要加一個 www.abc.example.com A 紀錄或別名,指到同一個 IP。

EasyEngine 申請 Lets Encrypt 有兩種模式

第一種,一開始建立網站時,就一起申請 Lets Encrypt 證書。

指令

ee site create example.com --wp --letsencrypt

第二種,已經有網站在運行了,之後再申請 Lets Encrypt 證書

指令

ee site update example.com --letsencrypt

原本的網站已經在運行了,就使用第二種方式申請證書,打完指令後會停在黃色字上,就不會動了,這時候是在申請證書中,請耐心等候。

Letsencrypt is currently in beta phase.
Do you wish to enable SSl now for in?
Type "y" to continue [n]:y
Downloading LetsEncrypt          [Done]
Let's Encrypt successfully setup for your site
Your certificate and chain have been saved at /etc/letsencrypt/live/example.com/fullchain.pem
Configuring Nginx SSL configuration
Adding /var/www/example.com/conf/nginx/ssl.conf
Adding /etc/nginx/conf.d/force-ssl-example.com.conf
Added HTTPS Force Redirection for Site  http://example.com
Creating Cron Job for cert auto-renewal
Reload : nginx     [OK]
Congratulations! Successfully Configured SSl for Site  https://example.com
Your cert will expire within 89 days.

完成證書的申請,先到 WordPress 後台設定網址為 https,如果不行就使用 phpMyAdmin 進入資料庫的方法,修改網址,找到 siteurl 與 home 這兩個數據,將 http://example.com 改為 https://example.com。

在試一次開啟網頁,可愛的小綠綠鎖頭圖示,已經跑出來了。

如果哪天突然不想用 SSL 證書了,也可以取消。

執行:

ee site update example.com --letsencrypt=off

注意目前 Lets Encrypt 提供的 SSL 證書效期為 90 天。90 天後還要再續訂一次許可證。但是每 90 天手動更新有可能會忘記,因此可以利用 Linux cron 提供自動更新 SSL 證書。

設定 1 個月續訂 SSL 證書 1 次

執行:

crontab -e
0 0 1 * * ee site update --le=renew --all 2> /dev/null

不要用自動更新的方式,也可以用手動方式更新證書。

ee site update example.com --letsencrypt=renew

此外,還可以檢查網站的狀態和 Lets Encrypt 到期日期:

ee site info example.com
HelloROOT
Follow me

Share

  • Add this entry to Hatena Bookmark

Follow Me

Comments

  1. yungke says:

    EasyEngine 最新版 ( 3.7.4 ),已經不需要手動去設置自動更新證書了。

    當你安裝好證書後,就幫你自動寫入 cron,每個星期日申請一次。