現在 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金鑰。 接下來開始安裝,如果大家實做過後有什麼問題,
使用 Certbot 申請 Let’s Encrypt SSL 金鑰
(1) 多網域時使用
依需求自行修改 certonly:僅申請憑證,不編輯 httpd.conf --apache:表示使用apache作為伺服器軟體 -w:網域所在的根目錄路徑 -d:連續請求的功能 --mail:SSL金鑰到期前寄送過期通知
certbot certonly --apache -w /var/www/html/ -d digit-seed.com -d www.digit-seed.com --email andy@digit-seed.com
(2) 單一網域時使用
certbot certonly --apache -w /var/www/html/ -d certbot.digit-seed.com --email andy@digit-seed.com
成功申請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.digit-seed.com Waiting for verification... Cleaning up challenges IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/certbot.digit-seed.com/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/certbot.digit-seed.com/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.digit-seed.com/
total 4 lrwxrwxrwx. 1 root root 46 Dec 12 14:54 cert.pem -> ../../archive/certbot.digit-seed.com/cert2.pem lrwxrwxrwx. 1 root root 47 Dec 12 14:54 chain.pem -> ../../archive/certbot.digit-seed.com/chain2.pem lrwxrwxrwx. 1 root root 51 Dec 12 14:54 fullchain.pem -> ../../archive/certbot.digit-seed.com/fullchain2.pem lrwxrwxrwx. 1 root root 49 Dec 12 14:54 privkey.pem -> ../../archive/certbot.digit-seed.com/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.digit-seed.com.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 自動續約過期金鑰
設定 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 random; import time; time.sleep(random.random() * 3600)' && certbot renew > /tmp/cert-bot_renew.log && systemctl reload httpd
certbot 常用指令
(1)列出所有憑證及到期日
certbot certificates
(2)測試是否能更新
certbot renew --dry-run
(2)手動立即更新SSL憑證
certbot renew

這個風風雨雨個社會 欲怎樣開花
少年家怎樣落地 咱攏是為著愛情來浪流連