Linux下certpot 免費搭建https協議

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

 

假如就放在/home

 

wget https://github.com/certbot/certbot/archive/master.zip

 

unzip master.zip

 

cd certbot-master/

 

./certbot-auto --help

 

./certbot-auto certonly --webroot --agree-tos -v -t --email loonghereqq.com -w /var/www/vduok.com/mch/web -d mch.vduok.com

如果報錯,再執行一遍

email爲郵箱,-w後面爲網站目錄,-d後面爲網站域名

 

然後生成的證書在/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;

    }

    location /storage/ {

        alias /var/www/vduok.com/storage/;

    }

}

server {

    server_name mch.vduok.com;

    location / {

        rewrite (.*) https://mch.vduok.com$1 permanent;

    }

}

 

service nginx reload

 

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

 

/home/certbot-master/certbot-auto renew

 

完成續期

 

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

 

創建腳本 renew-cert.sh

 

#!/bin/bash

 

/home/certbot-master/certbot-auto renew

 

/sbin/service nginx reload

 

保存腳本,並給予可執行權限

chmod a+x renew-cert.sh

 

寫入定時任務   crontab -e

30 4 * * 1 /home/renew-cert.sh >> /home/renew-cert.log 2>&1

 

保存並重啓crontd

service crond restart

 

完成自動更新證書

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章