下載certbot
# 下載certbot-auto
wget -c https://dl.eff.org/certbot-auto -P /usr/local/bin
# 設(shè)置可執(zhí)行權(quán)限
chmod +x /usr/local/bin/certbot-auto
# 查看版本,第一次運(yùn)行certbot-auto會(huì)安裝依賴
certbot-auto --version
申請證書
certbot-auto certonly -d *.example.com --manual --preferred-challenges dns --server https://acme-v02.api.letsencrypt.org/directory
- certonly 安裝模式
- -d 申請證書的域名,如果是通配符域名輸入 *.example.com
- --manual 手動(dòng)安裝插件
- --preferred-challenges dns 使用 DNS 方式校驗(yàn)域名所有權(quán)
- --server,Let's Encrypt ACME v2 版本使用的服務(wù)器不同于 v1 版本,需要顯示指定
# 輸入電子郵箱,用于續(xù)費(fèi)和安全通知
Enter email address (used for urgent renewal and security notices)
(Enter 'c' to cancel): xxx@163.com
# 服務(wù)條款,A:同意,C:取消
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A
# 是否訂閱相關(guān)的郵件
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, to share your email address with the Electronic Frontier Foundation, a founding partner of the Let's Encrypt project and the non-profit organization that
develops Certbot? We'd like to send you email about our work encrypting the web,EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: N
# IP綁定
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NOTE: The IP of this machine will be publicly logged as having requested this
certificate. If you're running certbot in manual mode on a machine that is not
your server, please ensure you're okay with that.
Are you OK with your IP being logged?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
配置DNS TXT記錄
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name
_acme-challenge.example.com with the following value:
pzBqECpVNkjt8gx76qVAYevMFg6n_8dfq-Xqr2f9dI8
Before continuing, verify the record is deployed.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue
- 到購買域名的服務(wù)商控制臺解析域名
- 添加一條TXT記錄
- 主機(jī)記錄:_acme-challenge.example.com
- 記錄值:pzBqECpVNkjt8gx76qVAYevMFg6n_8dfq-Xqr2f9dI8
- 記錄生效后,回車
Waiting for verification...
Cleaning up challenges
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/example.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/example.com/privkey.pem
Your cert will expire on 2020-12-21. To obtain a new or tweaked
version of this certificate in the future, simply run certbot-auto
again. To non-interactively renew *all* of your certificates, run
"certbot-auto renew"
- Your account credentials have been saved in your Certbot
configuration directory at /etc/letsencrypt. You should make a
secure backup of this folder now. This configuration directory will
also contain certificates and private keys obtained by Certbot so
making regular backups of this folder is ideal.
- If you like Certbot, please consider supporting our work by:
Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le
證書目錄:/etc/letsencrypt/live/example.com
ls /etc/letsencrypt/live/example.com
cert.pem chain.pem fullchain.pem privkey.pem README
自動(dòng)續(xù)訂
-
創(chuàng)建續(xù)訂證書腳本
touch /usr/local/bin/sslrenew.sh -
編輯腳本內(nèi)容
在sslrenew.sh文件中添加以下內(nèi)容certbot-auto renew
-
設(shè)置腳本可執(zhí)行
chmod +x /usr/local/bin/sslrenew.sh -
編輯定時(shí)任務(wù),每月1號執(zhí)行續(xù)訂操作
crontab -e添加定時(shí)邏輯
0 0 1 * * /usr/local/bin/sslrenew.sh
-
重新加載定時(shí)任務(wù)
service crond reload -
查看定時(shí)任務(wù)列表
crontab -l
配置nginx
server {
listen 443 ssl;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
ssl on;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
ssl_prefer_server_ciphers on;
ssl_certificate /etc/letsencrypt/live/example.com/cert.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
}
作者公眾號
