Skip to content
Menu
ecliptic's life
  • 關於
ecliptic's life
2021/12/142021/12/14

使用 Certbot 協助 HTTPS 設定 (Apache)

在架站之初,也是設定了很久,看了許多文章,想著一勞永逸, 之後再也不要回來管這些東西,結果在上個月我意外地方現憑證居然過期了,導致連進來本站時會跳出安全警示,想想,總不能因為我的流量不大,就不解決…結果,拖了半個月能解決,然後再拖了半個月再把這篇完成。

Certbot 安裝

也是看了很多,參考資料儘量已經附在最下方,總之決定使用 Certbot。這部份安裝的教學在 Certbot 網站上做得很好了,我的設備是樹梅派3b,使用 Apache 在 Debian 10 上,如果是其他的,也可以在網站裡面選擇。我節錄一下重點:

  1. 先安裝 snapd
sudo apt update
sudo apt install snapd

su root
apt update
apt install snapd
sudo snap install core

2. 確認 snapd 更新

sudo snap install core; sudo snap refresh core

3. 如果之前有安裝過 Certbot 需要解除安裝

sudo apt-get remove certbot

4. 安裝 Certbot

sudo snap install --classic certbot

5. 準備 Certbot 指令

sudo ln -s /snap/bin/certbot /usr/bin/certbot

使用 Certbot 半自動化取得憑證

主要有兩關,第一關:確定 Domain 是屬於我自己的。第二關:確定網站是屬於我自己的。

第一關:因為我要申請的是裸網域 (ecliptic.tw) 的憑證,所以好像只能用 –manual,另外連帶的把其他的子網域也一同申請好了,將來有其他需要的話,就可以直接用了。

sudo certbot certonly --manual -m ecliptic@mail.ecliptic.tw -d 'ecliptic.tw' -d '*.ecliptic.tw'

接下來會看到,他會停在這等你設定完

Please deploy a DNS TXT record under the name:

_acme-challenge.ecliptic.tw.

with the following value:

cf6dd5e292fd79d5fc07fadc03239af1e5340364daf

因為要確定整個 Domain 都是我自己的,這時離開 Terminal,去 DNS 代管設定,我的是在 Cloudflare。在 Cloudflare DNS 上增加一個記錄,Type 選擇 TXT,Content 就將上面那段貼上,好了按 Save。

回到 Terminal 內會看到連結,可以使用它提供的連結確定設定的是不是正確。可以的話按 Enter,如果有通過的話,就可以邁向第二關了。

這時 Terminal 會提示你到你的網站上增加一個檔案,而檔案的內容要包含特定的文字,檔名和檔案內容都要完全正確。這步也不難,就照著增加檔案就好了。

Create a file containing just this data:

suMicRYlgpah4yI4JGN4-sliclUoYaoSA42B0r7zwE4.yvoNtn6gTLugRRl5HnyGKU8mtLq-h-Ho8TkWNN6Na5Q

And make it available on your web server at this URL:

http://ecliptic.tw/.well-known/acme-challenge/suMicRYlgpah4yI4JGN4-sliclUoYaoSA42B0r7zwE4

(This must be set up in addition to the previous challenges; do not remove,
replace, or undo the previous challenge tasks yet.)

好了之後,繼續 Enter。一切順利的話,就可以看到成功訊息了!


Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/ecliptic.tw/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/ecliptic.tw/privkey.pem
This certificate expires on 2022-03-01.
These files will be updated when the certificate renews.

這時打開 /etc/apache2/sites-available/default-ssl.conf 檔,確定兩項證書位置輸入正確:


SSLCertificateFile      "/etc/letsencrypt/live/ecliptic.tw/fullchain.pem"
SSLCertificateKeyFile   "/etc/letsencrypt/live/ecliptic.tw/privkey.pem"

這時應該就搞定 HTTPS 設定了,可以使用 https://ecliptic.tw 試看看。(有可能要重啟 apache 服務)

參考資料

  • https://blog.miniasp.com/post/2021/02/11/Create-SSL-TLS-certificates-from-LetsEncrypt-using-Certbot
  • https://andyyou.github.io/2019/04/13/how-to-use-certbot/
  • https://caloskao.org/ubuntu-use-certbot-to-automatically-update-lets-encrypt-certificate-authority/
  • https://www.vedfolnir.com/get-free-ssl-certificates-from-certbot-25164.html
  • https://www.digit-seed.com/centos7-certbot-lets_encrypt_ssl/

發佈留言 取消回覆

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

Recent Posts

  • macOS Montery 12.2 藍牙導致耗電異常
  • 使用 command line 指令為 macOS 進行更新
  • 使用 Certbot 協助 HTTPS 設定 (Apache)
  • sshfs 將遠端伺服器上的硬碟掛載到 macOS 本機端
  • Firefox 容器使用:瀏覽器多開,各分頁獨立

Recent Comments

  1. 「ecliptic」於〈Mac上將 iOS 的備份移至(多重)外接硬碟〉發佈留言
  2. 「ecliptic」於〈Hello world! 這裡的第一篇文章〉發佈留言
  3. 「Hiraku」於〈Mac上將 iOS 的備份移至(多重)外接硬碟〉發佈留言
  4. 「Hiraku」於〈Hello world! 這裡的第一篇文章〉發佈留言

Archives

  • 2022 年 2 月
  • 2022 年 1 月
  • 2021 年 12 月
  • 2021 年 11 月
  • 2021 年 10 月
  • 2021 年 8 月

Categories

  • macOS實用技能
  • 實用工具
  • 本站公告
  • 架站工具
  • 資料蒐集處理
©2022 ecliptic's life | Powered by WordPress and Superb Themes!