1. 程式人生 > >使用acme.sh獲取並定期自動更新https證書

使用acme.sh獲取並定期自動更新https證書

關於let's encrypt和acme.sh的簡介

Let’s Encrypt is a free, automated, and open Certificate Authority.

acme.sh 實現了 acme 協議, 可以從 let‘s encrypt 生成免費的證書.

安裝,使用acme.sh

  • 推薦使用root使用者安裝
sudo su root
  • 安裝命令
curl  https://get.acme.sh | sh
  • 生成ssl證書

使用webroot方式

acme.sh  --issue -d blog.lomot.cn  --webroot  /var/www/blog.lomot.cn/

或者可以使用nginx方式,具體還有其他的方法參考acme.sh專案的github

acme.sh  --issue -d blog.lomot.cn  --nginx
  • copy證書
acme.sh --installcert -d blog.lomot.cn --key-file /etc/nginx/ssl/blog.lomot.cn.key --fullchain-file /etc/nginx/ssl/blog.lomot.cn.cer --reloadcmd "service nginx force-reload"
  • 應用證書

這裡只給出nginx的方法:

例如網址是blog.lomot.cn 在/etc/nginx/nginx.conf
中新增如下

    server {
        listen 80;
        server_name blog.lomot.cn;
        rewrite ^(.*)$  https://$host$1 permanent;
    }

    server {
        listen 443;
        server_name blog.lomot.cn;
        ssl on;
        ssl_certificate  /etc/nginx/ssl/blog.lomot.cn.cer;
        ssl_certificate_key /etc/nginx/ssl/blog.lomot.cn.key;
        ssl_session_timeout 5m;
        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 / {
            proxy_set_header   X-Real-IP $remote_addr;
            proxy_set_header   Host      $http_host;
            proxy_pass         http://localhost:3000;
            proxy_set_header REMOTE-HOST $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }

證書自動更新

目前證書在 60 天以後會自動更新, 你無需任何操作. 今後有可能會縮短這個時間, 不過都是自動的, 你不用關心.

更新acme.sh

目前由於 acme 協議和 letsencrypt CA 都在頻繁的更新, 因此 acme.sh 也經常更新以保持同步.

升級 acme.sh 到最新版 :

acme.sh --upgrade
如果你不想手動升級, 可以開啟自動升級:

acme.sh --upgrade --auto-upgrade
之後, acme.sh 就會自動保持更新了.

你也可以隨時關閉自動更新:

acme.sh --upgrade --auto-upgrade 0

引用

具體教程可以參考acme.sh的github
https://github.com/Neilpang/acme.sh



作者:lomot
連結:https://www.jianshu.com/p/8984bed9a784
來源:簡書
簡書著作權歸作者所有,任何形式的轉載都請聯絡作者獲得授權並註明出處。