天天看點

nginx 擷取https 免費證書(最新)擷取certbot工具

續上次寫https獲驗證書以後 ,現在已經無法使用了

[root@localhost ~]# ./certbot-auto  renew
Upgrading certbot-auto 1.10.1 to 1.11.0...
Couldn't download https://raw.githubusercontent.com/certbot/certbot/v1.11.0/letsencrypt-auto-source/letsencrypt-auto. <urlopen error [Errno 111] Connection refused>
           

發現報錯 Couldn’t download

https://raw.githubusercontent.com

原因是:certbot-auto将始終嘗試從最新版本中擷取自身的最新版本

于是就有了今天這個文章,嘗試在官網尋找了最新的certbot來解決證書問題

certbot官網位址:

https://certbot.eff.org/

mySystem:Ubuntu16.04系統

擷取certbot工具

1.安裝snap

介紹

Snap是一個全新的軟體包架構,它與其它包管理器的差別在于snap安裝的app互相之間是高度隔離的,減少了互相引用. 避免了很多沖突問題. 不過這也導緻了其占用的磁盤比較多.

安裝

# apt安裝
apt install -y snapd snapcraft

# yum安裝
# 安裝 EPEL
yum install epel-release;
# 安裝 snapd
yum install snapd;
# 添加snap啟動通信 socket
systemctl enable --now snapd.socket;
# 建立連結(snap軟體包一般安裝在/snap目錄下)
ln -s /var/lib/snapd/snap /snap;           

2.安裝certbot核心庫

sudo snap install core; sudo snap refresh core;           

3.安裝certbot

sudo snap install --classic certbot
           

4.添加軟鍊

sudo ln -s /snap/bin/certbot /usr/bin/certbot           

5.nginx 添加https

certbot --nginx
           

使用“certbot --nginx” 來配置https的時候 需要在nginx 裡有相關的server配置

server{
        server_name  www.xxxx.com;
        location / {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

        client_max_body_size 100M;
        proxy_pass  http://127.0.0.1:9122;
        
        }
}
           

關于自動續簽

由于certbot的免費時間隻有90天,是以需要每兩個月上去續簽一次

參考以前寫的 現在改用certbot

#檢視SSL證書的過期時間

./certbot-auto certificates 

#更新證書

./certbot-auto renew

#如果不需要傳回的資訊,可以用靜默方式

./certbot-auto renew --quiet

#強制更新證書指令:

./certbot-auto renew --force-renew

#手動更新

./certbot-auto renew -v

#自動更新

./certbot-auto renew --quiet --no-self-upgrade

#定時更新

加入定時任務  crontab -e 

0 3 */15 * * /root/certbot-auto renew --renew-hook "/etc/init.d/nginx reload" >> /root/renew.log

#每十五天的淩晨三點 運作一次更新的腳本,并執行 nginx 重新開機 并輸出日志檔案

#我的certbot-auto包是在root目錄下的

           

繼續閱讀