此方法不能申请通配符证书(*.example.com)

webroot 模式

Let’s Encrypt 只需要验证域名控制权,它会在你的网站目录里放一个临时文件,比如:

http://example.com/.well-known/acme-challenge/xxxxx

CA 验证访问成功即可签发证书。

1、安装 Certbot

CentOS 7

sudo yum install epel-release -y
sudo yum install certbot -y

CentOS 8 / Stream(截图环境)

sudo dnf install epel-release -y
sudo dnf install certbot -y

安装成功后验证:

certbot –version

2、确认网站根目录

/var/www/html

3、申请证书

sudo certbot certonly –webroot -w /var/www/html -d example.com -d www.example.com

解释:

sudo
以管理员(root)权限运行,因为 Certbot 需要写入系统证书目录(通常是 /etc/letsencrypt)并可能重载服务。

certbot
Let’s Encrypt 推荐的客户端程序(ACME 客户端)。它负责与 CA(Let’s Encrypt)交互、完成验证(challenge)、并在成功后下载证书。

certonly
只获取证书(certificate only),不让 Certbot 自动修改/安装到你 Web 服务器的配置文件。适合你想手动管理 Apache 配置的情形。
(如果你想让 Certbot 自动配置 Apache,可以用 certbot –apache,但题主之前说不修改 Apache。)

–webroot
指定使用 webroot(HTTP-01)验证:Certbot 会在你给的 web 根目录下(-w 指定)创建一个临时文件(例如:.well-known/acme-challenge/<随机字符串>)。Let’s Encrypt 的验证服务器会通过 http://yourdomain/.well-known/acme-challenge/… 访问该文件来确认你控制该域名。
优点:不需要停止 Apache,不需要占用端口 80;缺点:必须能把验证文件通过 HTTP 正确访问到(没有被 rewrite、权限阻挡或 CDN 缓存影响)。

-w /var/www/html
webroot 的路径(网站根目录)。Certbot 在该目录下创建 .well-known/acme-challenge/ 并放置验证文件。
要求:这个路径对外访问时对应你的 example.com 的 DocumentRoot(或能映射到该路径)。如果你的 Apache 为不同域使用不同根目录,给每个域分别指定 -w(见下例)。

-d example.com -d www.example.com
指定要为哪些域名(subject alternative names,SANs)颁发证书。-d 可以重复多次来包含多个主机名。
证书将同时包含 example.com 和 www.example.com,访问任一域名时都受该证书保护。

成功后输出类似:

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

整个过程 Apache 不会被停止或重启

作者 admin

百度广告效果展示