Linux下certpot 免費搭建https協議 並自動更新(2)

acentos配置Let's Encrypt並自動更新

檢測Git指令

#檢查系統是否安裝git
git  --version
如果沒有安裝Git的話,執行以下命令進行安裝(如果檢測到已安裝則略過)

#git 安裝
yum install git


假如就放在/home下

#獲取letsencrypt
git clone https://github.com/letsencrypt/letsencrypt

cd letsencrypt/

./letsencrypt-auto --help

# 獲取證書
關於域名驗證和證書的獲取安裝,上面提到了5種方式:
--apache, 
--standalone, 
--nginx, 
--webroot 
--manual,請根據實際情況選擇其一

 ./letsencrypt-auto certonly --webroot --email [email protected] -d 123.top -d www.23456.top

然後生成的證書在/etc/letsencrypt/live/下

編輯nginx配置文件    //根據自己情況改變
server {
    listen 443;
    server_name mch.vduok.com;
    ssl on;
    root /var/www/vduok.com/merchant/web;
    index index.html index.php;
    ssl_certificate "/etc/letsencrypt/live/mch.vduok.com/fullchain.pem";
    ssl_certificate_key "/etc/letsencrypt/live/mch.vduok.com/privkey.pem";
    ssl_session_cache shared:SSL:1m;
    ssl_session_timeout  10m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
    ssl_prefer_server_ciphers on;
    location / {
        try_files $uri $uri/ /index.php$is_args$query_string;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}
server {
    server_name mch.vduok.com;
    location / {
        rewrite (.*) https://mch.vduok.com$1 permanent;
    }
}

service nginx reload

即可完成SSL的配置,有效期3個月,快到期會自動往上面的郵箱發郵件,後臺renew續期即可

/home/letsencrypt/certbot-auto renew

完成續期

加入定時任務,設置了每週一凌晨4點30自動更新證書,並自動重啓nginx服務,證書在到期前30天內才能更新,多餘的更新會自動忽略掉的,每週更新還有一個好處是更新可能會失敗,這樣最多還有4次的嘗試機會來保證不會過期.

創建腳本 vim /home/updatessl.sh    //創建一個名字爲updatessl的腳本

#!/bin/bash

/home/letsencrypt/certbot-auto renew

/sbin/service nginx reload

保存腳本,並給予可執行權限
chmod a+x updatessl.sh

寫入定時任務   crontab -e
30 4 * * 1 /home/updatessl.sh >> /home/updatessl.log 2>&1

保存並重啓crontd
service crond restart

完成自動更新證書

發佈了21 篇原創文章 · 獲贊 5 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章