今天端午節,下雨閒閒沒事做
就來實裝Let's Encrypt SSL憑證

系統環境

指令
cat /etc/centos-release
印出
CentOS release 6.8 (Final)

其實去年也有試著裝過Let's Encrypt SSL憑證
但是沒有成功,主要是在安裝的過程中
一直重覆申請憑證就被擋了...

輸入網址即可查詢 Let's Encrypt 申請紀錄的資訊
crt.sh Certificate Search

目前Let's Encrypt SSL憑證安裝已經非常簡單
只需下載官網提供的安裝程式即可
去年試裝時用了一堆第三方的一鍵安裝,搞得被封鎖好幾個月...

首先來certbot.eff.org
指定安裝環境

我的是Centos6 +Apache


就會顯示完整的安裝流程!!!

這邊要注意的是
在執行 certbot-auto --apache certonly
就算是用root登入也要使用 sudo
我的完整指令
sudo ./certbot-auto --apache certonly --cert-name smile.hsu.cc -d smilehsu.cc,www.smilehsu.cc

在網路上google很多Let's Encrypt SSL 安裝文
寫到裝好憑證後就結束了...
網址是不會自動加綠鎖頭的!


接下來要設定 httpd 的conf檔

先修改 /etc/httpd/conf/httpd.conf
NameVirtualHost *:443

再來修改
/etc/httpd/conf.d/ssl.conf
ServerName *:443

<VirtualHost *:443>
ServerAdmin webmaster@smilehsu.cc
DocumentRoot /var/www/html/wordpress
ServerName smilehsu.cc
ErrorLog logs/smilehsu.cc-error_log
CustomLog logs/smilehsu.cc-access_log common



<Directory /var/www/html/wordpress>
AllowOverride All
</Directory>

SSLEngine on
SSLCertificateFile "/etc/letsencrypt/live/smile.hsu.cc/cert.pem"
SSLCertificateKeyFile "/etc/letsencrypt/live/smile.hsu.cc/privkey.pem"
SSLCertificateChainFile "/etc/letsencrypt/live/smile.hsu.cc/chain.pem"

</VirtualHost>


<VirtualHost *:443>
ServerAdmin webmaster@smilehsu.cc
DocumentRoot /var/www/html/wordpress
ServerName www.smilehsu.cc
ErrorLog logs/smilehsu.cc-error_log
CustomLog logs/smilehsu.cc-access_log common



<Directory /var/www/html/wordpress>
AllowOverride All
</Directory>

SSLEngine on
SSLCertificateFile "/etc/letsencrypt/live/smile.hsu.cc/cert.pem"
SSLCertificateKeyFile "/etc/letsencrypt/live/smile.hsu.cc/privkey.pem"
SSLCertificateChainFile "/etc/letsencrypt/live/smile.hsu.cc/chain.pem"

</VirtualHost>

如果沒問題的話重新restart httpd應該是OK的

接下來,打開網站後台
把預設的網址改成https://smilehsu.cc
退出後台,看看首頁有沒有變成綠鎖頭


結果首頁還不是綠鎖頭,打開其他文章頁面
發現有些已經是綠鎖頭,但有些不是
到這邊已經可以確定SSL憑證已經正常運作
目前的問題出現在wordpress身上

用chrome檢查不是綠鎖頭的頁面錯誤訊息
發現網站的圖片尚未更改成https://

這邊有三種方法可以解決:

1.手動編輯文章頁面,將所有的圖片連結改成https://
(一開始我就是用這種最笨的方法)

2.用phpmyadmin直接修改資料庫
UPDATE wp_posts SET guid = REPLACE (

guid,

‘http://smilehsu.cc’,

‘https://smilehsu.cc’);

3.安裝wordpress外掛 Search Rexge
(手動修改到一半,受不了了,求助google大神給的答案)


最後Let's Encrypt SSL憑證有效期限是90天,所以需要renew
certbot.eff.org已經有提供renew的方法
這邊提供其他的方式

auto_renew.sh
letsencrypt_path="/root/"
log_file="/var/log/ssl-auto-renew.log"

#開始更新憑證
service httpd stop
$letsencrypt_path/certbot-auto renew > $log_file
echo "Renew time:" >> $log_file
date >> $log_file
service httpd start

設定每天早上6點執行一次

crontab -e

0 6 */1 * * sh /root/auto_renew.sh




備註:

1.很久沒花那麼多時間打文章了
全拜換新筆電的關係...XDD

2.將預設編輯器改成nano
export EDITOR=nano

3.資料引用來源:
1.WordPress Search Regex外掛,批次修改所有文章的內容,一鍵快速取代
2.安裝綠色鎖頭後,如何批次修改內文網址
3.[WP外掛]如何批次修改MySQL中的資料
4.【CentOS6/Apache】安裝 Let's Encrypt 憑證
5.如何使用certbot自動更新SSL憑證 (CentOS 7, CentOS 6, Ubuntu)
6.LETSENCRYPT 自動更新憑證
arrow
arrow
    全站熱搜

    正義的胖虎 發表在 痞客邦 留言(0) 人氣()