使用certbot续期ssl证书renew时遇到问题

原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://blog.csdn.net/qq_19868745/article/details/72677709

遇到的问题如下:IMPORTANT NOTES:

 - The following errors were reported by the server:


   Domain: www.miling.online
   Type:   unauthorized
   Detail: Invalid response from
   http://www.miling.online/.well-known/acme-challenge/8IPPiMABwsHSwqSSTfZ5XMv7wD9sqXdO1pzOwFebdzg
   [2001:470:35:bf9::2]: 404


   To fix these errors, please make sure that your domain name was
   entered correctly and the DNS A record(s) for that domain
   contain(s) the right IP address.
[root@iZuf6istfz0zvz8dbdfyxxZ ~]# certbot-auto renew --force-renew
-bash: certbot-auto: command not found
[root@iZuf6istfz0zvz8dbdfyxxZ ~]# 
[root@iZuf6istfz0zvz8dbdfyxxZ ~]# 1
-bash: 1: command not found
[root@iZuf6istfz0zvz8dbdfyxxZ ~]# certbot renew --quiet
Attempting to renew cert from /etc/letsencrypt/renewal/www.miling.online.conf produced an unexpected error: Failed authorization procedure. www.miling.online (http-01): urn:acme:error:unauthorized :: The client lacks sufficient authorization :: Invalid response from http://www.miling.online/.well-known/acme-challenge/o30LM-8eAdn4IB8vX96Aa1Xgs6Mwc-5QjJNQ8mjl_Ns [2001:470:35:bf9::2]: 404. Skipping.


All renewal attempts failed. The following certs could not be renewed:
  /etc/letsencrypt/live/www.miling.online/fullchain.pem (failure)

1 renew failure(s), 0 parse failure(s)

最后查看了certbot的帮助


依次运行:

# service nginx stop

# certbot --force-renewal

# certbot certonly

# certbot renew --dry-run

# cerbot nginx start



需要注意的是service nginx stop/start,否则会出现问题


<think>我们参考了用户提供的引用内容,特别是引用[1]和引用[2]中关于使用Certbot配置Nginx SSL证书的方法。 另外,用户补充了一个注意事项:不要频繁获取证书,以免触发Let's Encrypt的限流措施。 我们将按照以下步骤来回答: 1. 安装CertbotNginx插件 2. 获取SSL证书(注意:首次获取需要验证域名所有权) 3. 配置Nginx使用SSL证书 4. 设置自动更新证书的定任务(注意间间隔设置,避免限流) 5. 附加注意事项(如端口开放、日志查看等) 注意:引用[1]中提到了定任务周期的错误,并给出了正确的定任务表达式:0 1 * */2 * (每两个月执行一次) 但实际上,Let's Encrypt的证书有效期是90天,我们建议在证书到期前30天内续期,通常设置为每月续期一次即可,但不要过于频繁(如每天)以免触发限流。 我们将定任务设置为每月的1号和15号的凌晨1点,这样比较安全。 同,引用[3]提供了在CentOS7上安装NginxCertbot的方法,但用户的问题是关于配置方法,因此我们以配置为主。 由于用户要求生成相关问题,我们在最后会提出几个相关问题。 </think>### 使用 CertbotNginx 上配置 SSL 证书的方法 以下是完整的配置流程,结合引用内容的关键要点: #### 1. 准备工作 - **安装 Nginx**(如未安装): ```bash # 添加 Nginx 官方源(CentOS 示例) cat > /etc/yum.repos.d/nginx.repo << 'EOF' [nginx-stable] name=nginx stable repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://nginx.org/keys/nginx_signing.key EOF yum clean all yum install nginx -y ``` [^3] - **安装 CertbotNginx 插件**: ```bash # Ubuntu/Debian sudo apt install certbot python3-certbot-nginx # CentOS sudo yum install certbot python3-certbot-nginx ``` #### 2. 获取 SSL 证书 ```bash sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com ``` - 首次运行按提示完成域名验证 - 自动修改 Nginx 配置启用 HTTPS - **注意**:避免频繁执行,可能触发 Let's Encrypt 限流[^1] #### 3. 验证证书状态 ```bash sudo certbot certificates ``` 输出应显示证书路径和有效期(通常 90 天) #### 4. Nginx 配置要点 - 生成的配置文件位置:`/etc/nginx/sites-enabled/yourdomain.conf` - 关键配置片段: ```nginx server { listen 443 ssl; ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem; # 其他配置... } ``` - 测试配置并重载: ```bash sudo nginx -t # 测试配置语法 sudo systemctl reload nginx # 重载配置 ``` #### 5. HTTP 到 HTTPS 重定向 在 Nginx 配置中添加: ```nginx server { listen 80; server_name yourdomain.com www.yourdomain.com; return 301 https://$host$request_uri; # 强制跳转HTTPS } ``` #### 6. 自动续期设置 - 测试续期命令: ```bash sudo certbot renew --dry-run ``` - 创建定任务(每月执行两次): ```bash # 编辑 cron 任务 sudo crontab -e ``` 添加以下内容: ```cron 0 1 1,15 * * /usr/bin/certbot renew --quiet && systemctl reload nginx ``` **注意**:避免使用`--force-renewal`,除非必要[^1] #### 7. 故障排查 - **证书续期日志**:`/var/log/letsencrypt/letsencrypt.log` - **端口检查**:确保服务器开放 443 端口 - **SSL 状态检测**:[SSL Labs SSL Test](https://www.ssllabs.com/ssltest/) - **Nginx 重载失败**:尝试重启 `sudo systemctl restart nginx` #### 8. 卸载证书(如需) ```bash sudo certbot delete --cert-name yourdomain.com # 删除证书 sudo rm /etc/nginx/sites-enabled/yourdomain.conf # 移除Nginx配置 ``` [^2] > **注意事项**: > - 单次获取证书失败需间隔 1 小以上重试 > - 同一域名每周最多签发 5 张证书(Let's Encrypt 限制) > - 云服务器需配置安全组开放 443 端口
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值