Let's Encrypt Let's go(acme)

早就要想弄let’s encrypt 但是由于一直忙外加Let’s encrypt 初期復雜沒有弄。

今天要遷移一公司服務用到的https證書過期,故又弄起來let’s encrypt。它的簡介這里就不描述了,網上很多介紹的不錯直接進入主題。

1、獲取 Certbot 客戶端

wget https://dl.eff.org/certbot-auto
chmod a+x ./certbot-auto
./certbot-auto —help

2、配置 nginx 、驗證域名所有權

配置下nginx.conf 添加如下,這是必須要開80端口,let’s encrypt 服務器會到這里驗證,要開下面的驗證通道。配置完后進行重載

location ^~ /.well-known/acme-challenge/ {
default_type “text/plain”;
root html/authserver.eglsgame.com/;
}
location = /.well-known/acme-challenge/ {
return 404;
}

3、生成證書

證書生成成功后,會有 Congratulations 的提示,并告訴我們證書放在 /etc/letsencrypt/live 這個位置。(生成過程中卡在python install,必須要自己修改下源,步驟如下要不然過不去。

mkdir -p ~/.pip/
vi ~/.pip/pip.conf
添加
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com

./certbot-auto certonly --webroot -w /mnt/data/authresource/html/authserver.eglsgame.com --email limingjun@egls.cn -d authserver.eglsgame.com

4、配置 Nginx

ssl_certificate /etc/letsencrypt/live/authserver.eglsgame.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/authserver.eglsgame.com/privkey.pem;

這里還需要注意,必須要/etc/letsencrypt目錄權限,要不然會報權限問題。修改重載后瀏覽器就可以獲得漂亮的綠色。

5、配置更新

測試更新
./certbot-auto renew —dry-run

手動更新
/certbot-auto renew -v
添加自動更新腳本
vi /opt/letsencrypt/renew.sh

/opt/letsencrypt/certbot-auto renew —quiet —no-self-upgrade
cd /mnt/data/authresource
./ming -s reload

添加crontab

30 2 * * 0 /opt/letsencrypt/renew.sh 每周日執行一次

6、驗證服務器的https安全性

image.png

7、通配符域名申請

./certbot-auto certonly  -d *.eglsgame.com --manual --preferred-challenges dns
--server https://acme-v02.api.letsencrypt.org/directory 

certonly,表示安裝模式,Certbot 有安裝模式和驗證模式兩種類型的插件。
--manual 表示手動安裝插件,Certbot 有很多插件,不同的插件都可以申請證書,用戶可以根據需要自行選擇
-d 為那些主機申請證書,如果是通配符,輸入 *.newyingyong.cn(可以替換為你自己的域名)
--preferred-challenges dns,使用 DNS 方式校驗域名所有權
--server,Let's Encrypt ACME v2 版本使用的服務器不同于 v1 版本,需要顯示指定。

注意驗證時,需要添加TXT記錄


最近發現了acme很強大的工具

1,安裝

curl https://get.acme.sh | sh

2,生產域名證書

/root/.acme.sh/acme.sh --issue -d "xxx.daemon.com" -w /mnt/webserver/html/

3,生產nginx使用

/root/.acme.sh/acme.sh --install-cert -d "towngame.mengcloud.com.cn" --fullchain-file /etc/certs/towngame.mengcloud.com.cn/fullchain.pem --key-file /etc/certs/towngame.mengcloud.com.cn/privkey.pem  --reloadcmd     "sudo systemctl restart ming"
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容