GO TOP

LINE ID
andykao1026

Email
[email protected]

Address
10488 台北市中山區南京東路3段219號9樓

安裝Certbot 工具,與Let’s Encrypt 申請SSL金鑰憑證 ,自動更新SSL憑證- Centos7+Certbot

最新更新日期: 2023 年 6 月 15 日

現在 SSL金鑰憑證網站SEO 非常重要,可以說如果網站沒有使用 HTTPS協定 (HyperText Transfer Protocol Secure,以下簡稱HTTPS) ,基本上在搜尋引擎上,排名前10頁的機會都不會有,因此現行的網站使用HTTPS是必要的。

從今年起 Google Chrome 對HTTPS控管非常嚴格,只要未安裝SSL金鑰憑證的網站,就會在網址列中直接標出不安全的網站,當網站有正確安裝並啟用SSL金鑰憑證時,就會在網址列中直接標出安全的網站,此時網站中所有資訊就會經過加密後再傳送給對方,若真的有網路黑客想要從數據中擷取傳送資料,也只能獲得經過加密後的亂碼,難以解密出加密前的資訊。

(不安全的網站)
(安全的網站)

近期因架設了VPS伺服器,並無 cPanel 或是 Plesk 後台介面可以協助 申請SSL金鑰 以及 Let’s Encrypt SSL 自動更新 ,因此需要在 Centos7 系統中安裝 certbot 工具,跟 Let’s Encrypt 申請免費SSL金鑰,並利用 crontab 排程功能,自動更新SSL金鑰。 接下來開始安裝,如果大家實做過後有什麼問題,歡迎大家 填寫聯絡表單 ,小編會盡快回覆您的問題。

(1) 安裝 Certbot

yum install -y certbot

(2) 安裝 Python2-certbot-apache

yum install -y python2-certbot-apache

使用 Certbot 申請 Let’s Encrypt SSL 金鑰

(1) 多網域時使用

依需求自行修改
certonly:僅申請憑證,不編輯 httpd.conf
–apache:表示使用apache作為伺服器軟體
-w:網域所在的根目錄路徑
-d:連續請求的功能
–mail:SSL金鑰到期前寄送過期通知

certbot certonly –apache -w /var/www/html/ -d hopesmarketing.tw -d www.hopesmarketing.tw –email [email protected]

(2) 單一網域時使用

certbot certonly –apache -w /var/www/html/ -d certbot.hopesmarketing.tw –email [email protected]

成功申請SSL金鑰訊息

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Starting new HTTPS connection (1): acme-v02.api.letsencrypt.org
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for certbot.hopesmarketing.tw
Waiting for verification…
Cleaning up challenges

IMPORTANT NOTES:
– Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/certbot.hopesmarketing.tw/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/certbot.hopesmarketing.tw/privkey.pem
Your cert will expire on 2020-03-11. To obtain a new or tweaked version of this certificate in the future, simply run certbot again. To non-interactively renew *all* of your certificates, run “certbot renew”
– If you like Certbot, please consider supporting our work by:

Donating to ISRG / Let’s Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le

金鑰存放路徑

ll /etc/letsencrypt/live/certbot.hopesmarketing.tw/

total 4
lrwxrwxrwx. 1 root root 46 Dec 12 14:54 cert.pem -> ../../archive/certbot.hopesmarketing.tw/cert2.pem
lrwxrwxrwx. 1 root root 47 Dec 12 14:54 chain.pem -> ../../archive/certbot.hopesmarketing.tw/chain2.pem
lrwxrwxrwx. 1 root root 51 Dec 12 14:54 fullchain.pem -> ../../archive/certbot.hopesmarketing.tw/fullchain2.pem
lrwxrwxrwx. 1 root root 49 Dec 12 14:54 privkey.pem -> ../../archive/certbot.hopesmarketing.tw/privkey2.pem
-rw-r–r–. 1 root root 692 Dec 12 14:48 README

設定 Apache 參數

(1) 設定網域的 .conf 設定檔

因小編伺服器很多伺服器,所以小編的網域設定檔位於 /etc/httpd/conf.d

vi /etc/httpd/conf.d/026-certbot.hopesmarketing.tw.conf

依需求自行修改設定

VirtualHost *:443>
   <Directory /var/www/html/certbot.digit-seed.com>
      Options FollowSymLinks
      AllowOverride AuthConfig FileInfo Indexes
   </Directory>
      DocumentRoot /var/www/html/certbot.digit-seed.com
      ServerName certbot.digit-seed.com
      ServerAlias certbot.digit-seed.com
      SSLEngine on
      php_admin_value memory_limit 256M
     SSLCertificateFile /etc/letsencrypt/live/certbot.digit-seed.com/cert.pem
      SSLCertificateKeyFile /etc/letsencrypt/live/certbot.digit-seed.com/privkey.pem
      Include /etc/letsencrypt/options-ssl-apache.conf
      SSLCertificateChainFile /etc/letsencrypt/live/certbot.digit-seed.com/chain.pem
</VirtualHost>

(2) 重啟Apache之前,請先檢查是否有錯誤

apachectl -t
Syntax OK

(3) 重啟Apache,使 PHP 設定生效

systemctl restart httpd

贊助商連結

設定 crontab 自動續約過期金鑰

(1) 設定 crontab 設定檔

vi /etc/crontab

依需求自行修改
#因為免費憑證只有 3 個月的有效期, 所以自動檢查與更新是很重要
#certbot 就具有自動更新的功能, 可設定每天檢查三次(00:00 08:00 16:00), 執行時先隨機取 3600 中的一個秒數等待, 避免造成同時間大家一起連上 Let’s Encrypt 主機

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed
0 */8 * * * root python -c 'import rando

certbot 常用指令

(1)列出所有憑證及到期日

vi /etc/crontab

(2)測試是否能更新

certbot renew –dry-run

(3)手動立即更新SSL憑證

certbot renew

(總點閱次數 : 369 , 今日點閱數數 : 3 )
Andy 高嘉松
Andy 高嘉松

✓ 擁有8年MIS經驗以及使用WordPress製作過許多大型形象官網以及電商購物車網站
✓ 針對不同產業別給予專業建議及規劃,製作知名品牌網站,如黃色小鴨、佳世達等網站
✓ 熱愛研究網路服務、市場趨勢、用戶行為和動機, 熟悉GA、GTM、GSC工具
✓ 擅長數據分析、邏輯思考、資訊架構、系統整合

»購物車案例   »形象官網案例   »多語系網站案例

文章: 62
霍普行銷 Hope’s Marketing - 網站製作 | 平面設計 | 廣告投放 | 網路行銷