最後更新日期:2021 年 01 月 21 日

環境說明

OS: CentOS 7.6
網站伺服器:apache

安裝步驟

以下以 sudo 來做,如果不想用 sudo,可以直接用 root 的身分執行。

# 安裝相依套件
sudo yum install gcc libffi-devel python-devel openssl-devel git

# 安裝代理程式
cd /usr/share
sudo git clone https://github.com/letsencrypt/letsencrypt letsencrypt

# 透過代理程式自動安裝 apache SSL 服務
cd /usr/share/letsencrypt
sudo ./letsencrypt-auto --apache -d 你的網站域名
# 這會自動依你現有的 conf 檔,修改內容並產生另一個 ssl 的 conf 檔

# 重新啟動 apache
sudo systemctl restart httpd.service

手動更新 SSL 憑證

因為 Let's Encrypt SSL 憑證只有 90 天的期限,在期限到期之前,必須執行以下執令以更新憑證。

sudo /usr/share/letsencrypt/letsencrypt-auto renew

自動更新 SSL 憑證

如果不想手動執行,可以執行建立一個 script,並將其放入 /etc/cron.daily 目錄下,就可以每天自動執行。

script 內容如下:

#!/bin/bash
/usr/share/letsencrypt/letsencrypt-auto renew > /var/log/letsencrypt-auto.log

記得要把他的可執行權限設定好

sudo chmod +x /etc/cron.daily/letsencrypt-renew

參考資料

https://andyyou.github.io/2019/04/13/how-to-use-certbot/
https://blog.toright.com/posts/4837

Last modified: 2021-01-21

Author

Comments

Write a Reply or Comment

Your email address will not be published.