系統:Centos7.6
1、獲取certbot-auto並給予執行權限
wget https://dl.eff.org/certbot-auto
chmod u+x certbot-auto
2、開始申請證書
./certbot-auto --server https://acme-v02.api.letsencrypt.org/directory -d "*.tan1234.com" --manual --preferred-challenges dns-01 certonly
//中間的域名換成自己的
這裏是填郵箱,可以隨便寫,接受安全提醒和續期提醒的。
到下面這步就停下
到自己的域名解析去添加個文件解析,我的是阿里雲的
再另外開一個遠程窗口執行dig _acme-challenge.tan1234.com txt
出現上述提示的txt解析即可
再回來繼續回車執行下一步,出現下述提示則說明配置成功
配置證書存放在/etc/letsencrypt/live/tan1234.com/裏了
3.配置nginx支持ssl及http自動跳轉https
server {
server_name www.tan1234.com;
charset utf-8;
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/tan1234.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/tan1234.com/privkey.pem;
location / {
root html;
index index.html index.htm;
}
}
server {
listen 80;
server_name www.tan1234.com;
charset utf-8;
rewrite ^(.*)$ https://$server_name$1 permanent;
#指定PEM格式的證書文件
ssl_certificate
#指定PEM格式的私鑰文件
ssl_certificate_key
重啓下nginx即可http自動跳轉https,在 /etc/letsencrypt/renewal 目錄下,有網站的 renewal 的配置文件
vim /etc/letsencrypt/renewal/tan1234.com.conf
證書可以使用3個月,提前30天續期。
接下來只需要在阿里雲添加上解析,該域名下的所有三級域都會自動跳轉https了,共用這個證書。
4.更新證書
// 更新即將到期的證書
./certbot-auto renew
// 強制更新一個證書(這個證書也許還有很久纔到期)
./certbot-auto renew --force-renewal
將更新命令加入定時任務,讓它自動更新。