下载certbot-auto
| wget https://dl.eff.org/certbot-auto |
| |
| |
| |
| yum install epel-release //安装epel |
| yum install snapd //安装snapd |
| systemctl enable --now snapd.socket //启用snapd.socket |
| ln -s /var/lib/snapd/snap /snap //创建软链接 |
| snap install --classic certbot //安装certbot |
| ln -s /snap/bin/certbot /usr/bin/certbot //创建certbot软链接 |
| |
| |
| yum remove certbot //卸载certbot |
| rm /usr/local/bin/certbot-auto //删除安装文件 |
| rm -rf /opt/eff.org/certbot |
nginx检查是否开启http_ssl_module模块
不开启会出现nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf
通过 nginx -V查看是否开启该模块,如果没有开启,执行下面步骤开启(关闭 nginx,否则会出现 80 端口占用问题)
| cd /usr/local/src/nginx |
| ./configure --prefix=/usr/local/nginx --with-http_flv_module --with-http_ssl_module //安装ssl模块 |
| make |
| cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak //nginx做原有备份 |
| nginx -V //查看模块是否安装成功 |
| sudo systemctl start nginx //运行 nginx |
运行命令生成证书
| sudo certbot certonly -d "*.xxx.com" -d xxxx.com --manual --preferred-challenges dns-01 --server https://acme-v02.api.letsencrypt.org/directory(需要手动添加 txt 解析) |
| |
| sudo certbot certonly -d "*.xxx.com" -d xxxx.com --manual --preferred-challenges dns --manual-auth-hook "/etc/letsencrypt/renwal-hook/au.sh php aly add" --manual-cleanup-hook "/etc/letsencrypt/renwal-hook/au.sh php aly clean"(通过脚本调用域名解析 api,自动解析) |
| |
配置 nginx 配置文件
| listen [::]:443 ssl http2; |
| location / {return 301 https://$host$request_uri; |
| } |
| ssl_session_timeout 1d; |
| ssl_session_cache shared:SSL:10m; |
| ssl_session_tickets off; |
| ssl_protocols TLSv1.2 TLSv1.3; |
| ssl_certificate /home/www/letsencrypt/live/xxx.com/fullchain.pem; |
| ssl_certificate_key /home/www/letsencrypt/live/xxxx.com/privkey.pem; |
| ssl_trusted_certificate /home/www/letsencrypt/live/xxxx.com/chain.pem; |
| eturn 301 https://www.uchelian.com$request_uri; |
| |
证书自动续签
| |
| git clone https://github.com/ywdblog/certbot-letencrypt-wildcardcertificates-alydns-au |
| cd certbot-letencrypt-wildcardcertificates-alydns-au |
| chmod 0777 au.sh |
| |
| domain.ini文件添加您的根域名 |
| |
| |
| ALY_KEY 和 ALY_TOKEN:[阿里云 API key 和 Secrec 官方申请文档](https://help.aliyun.com/knowledge_detail/38738.html)。 |
| TXY_KEY 和 TXY_TOKEN:[腾讯云 API 密钥官方申请文档](https://console.cloud.tencent.com/cam/capi)。 |
| HWY_KEY 和 HWY_TOKEN: [华为云 API 密钥官方申请文档](https://support.huaweicloud.com/devg-apisign/api-sign-provide.html) |
| GODADDY_KEY 和 GODADDY_TOKEN:[GoDaddy API 密钥官方申请文档](https://developer.godaddy.com/getstarted)。 |
| |
| |
| PHP(>4以上版本均可) |
| au.sh php aly add/clean:PHP操作阿里云DNS,增加/清空DNS。 |
| au.sh php txy add/clean:PHP操作腾讯云DNS,增加/清空DNS。 |
| au.sh php godaddy add/clean:PHP操作GoDaddy DNS,增加/清空DNS。 |
| Python(支持2.7和3.7,无需任何第三方库) |
| au.sh python aly add/clean:Python操作阿里云DNS,增加/清空DNS。 |
| au.sh python txy add/clean:Python操作腾讯云DNS,增加/清空DNS。 |
| au.sh python hwy add/clean:Python操作华为云DNS,增加/清空DNS。 |
| au.sh python godaddy add/clean:Python操作GoDaddy DNS,增加/清空DNS。 |
| |
| |
| |
| 1 1 */1 * * root certbot-auto renew --manual --preferred-challenges dns --manual-auth-hook "/脚本目录/au.sh php aly add" --manual-cleanup-hook "/脚本目录/au.sh php aly clean" |