AI写作智能体 自主规划任务,支持联网查询和网页读取,多模态高效创作各类分析报告、商业计划、营销方案、教学内容等。 广告
[TOC] > [centos 本地服务器配置证书](https://cloud.tencent.com/developer/article/2432708) ## cerbot - 自动申请 SSL/TLS 证书 - 自动续期证书(证书有效期为90天) - 自动配置 Web 服务器(如 Nginx、Apache) - 自动管理多个域名的证书 ## 教程 **安装** ``` yum install epel-release -y yum install certbot -y ``` **申请域名** ``` > certbot certonly -d *.test.com --manual --preferred-challenges dns > ... > dns-01 challenge for tacn.com.cn - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Please deploy a DNS TXT record under the name _acme-challenge.tacn.com.cn with the following value: urBO4JqXHgu3H7xECBeEFRV1BOR_lMfw_RuKH69C5dQ Before continuing, verify the record is deployed. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Press Enter to Continue ``` 在这一步时, 进入云服务器的域名管理页面->[解析]->[添加记录],记录类型选择 TEXT,之后再点击 回车,就会在指定目录下生成 ``` /etc/letsencrypt/live/test.cn/fullchain.pem /etc/letsencrypt/live/test.cn/privkey.pem ``` **配置证书** ``` listen 443 ssl http2; ssl_certificate /etc/letsencrypt/live/xxx.cn/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/xxx.cn/privkey.pem; ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; server_name test.cn www.test.cn ; ``` **手动续** 再次执行之前的程序 ``` > certbot certonly -d *.test.com --manual --preferred-challenges dns ``` 并且配置新的 TXT 的域名解析 **自动续费** 1. 直接通过 Certbot 通过DNS方式申请域名证书后,因为在续订时需要更新 DNS 记录,所以使用[certbot-dns-aliyun](https://github.com/justjavac/certbot-dns-aliyun)解决阿里云 DNS 不能自动为通配符证书续期的问题 1. 续要创建 RAM 用户,并且赋予 `dns` 的相关权限,[相关文档](https://help.aliyun.com/zh/ram/user-guide/create-a-ram-user?spm=5176.2020520153.console-base_help.dexternal.211e336acVK4Nk) 2. 通过`aliyun ecs DescribeRegions ` 验证auth 是否通过 安装 aliyun cli 工具 ``` wget https://aliyuncli.alicdn.com/aliyun-cli-linux-latest-amd64.tgz tar xzvf aliyun-cli-linux-latest-amd64.tgz sudo cp aliyun /usr/local/bin rm aliyun ``` 安装 certbot-dns-aliyun 插件 ``` wget https://cdn.jsdelivr.net/gh/justjavac/certbot-dns-aliyun@main/alidns.sh sudo cp alidns.sh /usr/local/bin sudo chmod +x /usr/local/bin/alidns.sh sudo ln -s /usr/local/bin/alidns.sh /usr/local/bin/alidns rm alidns.sh ``` 申请证书 ``` certbot certonly -d *.example.com --manual --preferred-challenges dns --manual-auth-hook "alidns" --manual-cleanup-hook "alidns clean" --dry-run ``` 正式申请时去掉` --dry-run` 参数: 证书续期 ``` certbot renew --manual --preferred-challenges dns --manual-auth-hook "alidns" --manual-cleanup-hook "alidns clean" --dry-run ``` 添加定时任务 ``` > crontab -e > 1 1 */1 * * certbot renew --quiet --preferred-challenges dns --manual-auth-hook "alidns" --manual-cleanup-hook "alidns clean" --deploy-hook "nginx -s reload" ``` > 每天的凌晨 1:01 执行一次任务