https://imququ.com/post/letsencrypt-certificate.htmlhtml
一、python
openssl genrsa 4096 > account.key
二、私鑰nginx
openssl genrsa 4096 > domain.key
三、csr文件生成git
DNS域名,能夠多個,都要能夠訪問,注意用到了上面生成的文件github
openssl req -new -sha256 -key domain.key -subj "/" -reqexts SAN -config <(cat /etc/ssl/openssl.cnf <(printf "[SAN]\nsubjectAltName=DNS:yoursite.com,DNS:www.yoursite.com")) > domain.csr
其中,openssl.cnf文件位置,能夠查找:shell
find / -name 'openssl.cnf'
4.一、驗證準備bash
目錄dom
mkdir ~/www/challenges/post
訪問引導,注意目錄,不要忘記reload生效spa
server {
listen 80; server_name www.yoursite.com yoursite.com; #驗證訪問 location ^~ /.well-known/acme-challenge/ { alias /home/xxx/www/challenges/; try_files $uri =404; } location / {
#其餘訪問轉向https rewrite ^/(.*)$ https://yoursite.com/$1 permanent; } }
4.2 腳本文件
https://github.com/diafygi/acme-tiny 須要及時更新
5 驗證
注意用到了上面生成的兩個文件,並提供驗證目錄
python acme_tiny.py --account-key ./account.key --csr ./domain.csr --acme-dir ~/www/challenges/ > ./signed.crt
經過驗證後,當前目錄下就會生成一個 signed.crt
證書文件。
6 合併證書
wget -O - https://letsencrypt.org/certs/lets-encrypt-x3-cross-signed.pem > intermediate.pem cat signed.crt intermediate.pem > chained.pem
7開啓(nginx配置,其餘和http配置同樣)
server { server_name YOUR_DOMAINNAME_HERE; listen 443; ssl on; ssl_certificate ~/www/ssl/chained.pem; ssl_certificate_key ~/www/ssl/domain.key; }
6自動更新腳本
Let's Encrypt 簽發的證書只有 90 天有效期,用腳本按期更新。
腳本內容和上面步驟同樣,驗證並得到證書,合併證書,最後重載nginx,注意目錄
#!/bin/bash cd /home/xxx/www/ssl/ python acme_tiny.py --account-key account.key --csr domain.csr --acme-dir /home/xxx/www/challenges/ > signed.crt || exit wget -O - https://letsencrypt.org/certs/lets-encrypt-x3-cross-signed.pem > intermediate.pem cat signed.crt intermediate.pem > chained.pem service nginx reload
7按期執行腳本
可執行權限
chmod a+x renew_cert.sh
按期執行(每個月一次)
0 0 1 * * /home/xxx/shell/renew_cert.sh >/dev/null 2>&1