转载请注明出处:小锋学长生活大爆炸[xfxuezhagn.cn]
如果本文帮助到了你,欢迎[点赞、收藏、关注]哦~
目录
Certbot failed to authenticate some domains
要为 Apache 申请免费的 SSL 证书,可以使用 Let's Encrypt 提供的免费证书,通过 Certbot 工具来自动化获取和安装证书。
安装教程
1. 安装 Certbot
sudo apt-get update
sudo apt-get install certbot
2. 获取证书
-
运行以下命令来获取证书:
sudo certbot --apache -d yourdomain.com
-
将
yourdomain.com
替换为你的实际域名。 -
Certbot 会自动验证你的域名,并生成 SSL 证书。
-
3. 配置 Apache 使用 SSL 证书
注意,certbot会自动修改你的default-ssl.conf来指向证书文件,所以一般来说“不用修改配置文件”。当然也可以再次检查一下。
-
Certbot 通常会自动配置 Apache 使用 SSL 证书,但如果你需要手动配置,可以按照以下步骤操作:
-
找到证书文件:证书文件通常存放在
/etc/letsencrypt/live/yourdomain.com/
目录中。 -
编辑 Apache 配置文件:编辑位于
/etc/apache2/sites-available/
目录下的虚拟主机文件,例如yourdomain.com.conf
,并确保有以下 SSL 相关的配置:<VirtualHost *:443> ServerName yourdomain.com DocumentRoot /var/www/yourdomain.com/html SSLEngine on SSLCertificateFile /etc/letsencrypt/live/yourdomain.com/cert.pem SSLCertificateKeyFile /etc/letsencrypt/live/yourdomain.com/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/yourdomain.com/chain.pem # 其他配置... </VirtualHost>
-
启用 SSL 模块:
sudo a2enmod ssl
-
重启 Apache:
sudo systemctl restart apache2
-
4. 测试配置
-
使用浏览器访问你的网站,检查是否显示 HTTPS 和安全锁图标。
-
也可以使用 SSL 测试工具(如 [SSL Labs](https://www.ssllabs.com/ssltest/))来检查你的 HTTPS 配置是否正确。
5. 自动续期
-
Let's Encrypt 的证书有效期为 90 天,Certbot 会自动处理续期。你也可以手动运行以下命令来测试续期:
sudo certbot renew
报错处理
Certbot failed to authenticate some domains
重新运行 Certbot:
-
重新安装并运行 Certbot 获取证书:
sudo apt install --reinstall certbot
sudo certbot --apache -d xfxuezhang.cn -d www.xfxuezhang.cn
- 重启apache服务:
sudo systemctl restart apache2
Killed
- 多执行几次
sudo certbot --apache -d xfxuezhang.cn -d www.xfxuezhang.cn