【草稿】【Wordpress #10】自架網站 #4 | 透過 Let's Encrypt 來獲得免費的 SSL 憑證,並撰寫 crontab 定期更新

前言

此筆記目前尚未整理完成,如需學習完整內容可參考隨附的 reference,或自行 google 搜尋
但因為作者要整理的筆記太多,如果想早點看到整理後的文章,可以下方留言「期待整理」之類的… 我會努力找時間優先整理!

Let’s Encrypt 介紹

Let’s Encrypt 提供免費的 SSL 憑證,
不過免費的代價就是要對終端機有一定的熟悉度,才能夠方便的使用。

如果覺得困難,付費請主機商幫忙用也是一個選擇,畢竟專業本身就有其價值。

step 1. 安裝 snapd, certbot

在擁有一台自己的主機後,這裡以 ubuntu OS、示範,
其他版本的OS與服務」,請從以下連結找對應版本的教學進行學習。

step 1-1. 登入 ssh 主機

我們 ssh 登入主機,準備進行安裝

step 1-2. 安裝 snapd

通常比較新版的 ubuntu 已經有內建,
不過還是可以下以下指令,
有安裝過他會提示已經安裝。

sudo snap install core; sudo snap refresh core

step 1-3. 移除系統現有的 certbot

sudo apt-get remove certbot

step 1-4. 透過 snap 安裝 certbot

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

step 1-6. 執行 certbot

  • 在網站已經執行的當下,建立新的憑證
sudo certbot certonly --webroot

輸入自己的網域

redirect

in Networking -> Domains -> Create new record -> A

A:

HOSTNAME: @ 
WILL DIRECT TO: <ip>

將 wordpress ip 用 domain name 取代

GUI 解法

進到 wordpress 後台,
設定 -> 一般

  • WordPress 位址 (網址)
  • 網站位址 (網址)

修改成自己的 domain name

command line 解法

# vim wp-config.php

# 修改
define('WP_SITEURL', 'http://DOMAIN.COM/');
define('WP_HOME', 'http://DOMAIN.COM/');

error

問題1

Failed to renew certificate howard2.mousems.me with error: Could not bind TCP port 80 because it is already in use by another process on this system (such as a web server). Please stop the program in question and then try again.
  • 解法:
sudo systemctl stop apache2

問題2

Another instance of Certbot is already running.
  • 解法:
  ps -ef | grep certbot

去 kill 他!

[solved] Another instance of Certbot is already running

Reference