参考
Certbot 免费申请证书
安装Certbot
sudo apt install certbot安装Certbotcertbot --version查看版本,验证是否安装成功。
申请证书
certbot certonly -d *.exwckv.top -w /var/www/html --manual --preferred-challenges http获取域名证书certonly这个选项告诉Certbot你只需要获取或者更新证书,并不会自动安装它到你的web服务器配置中。-d指定域名 如*.baidu.com-w指定了你的网站根目录的位置,Certbot 将在这个目录下创建用于验证的文件。--manual指定手动模式,手动模式下,Certbot不会自动安装证书到你的web服务器配置中。--preferred-challenges指定验证方式包括http和dns。注意:对于通配符域名(如 *.example.com),Let’s Encrypt 要求必须使用 DNS 验证而不是 HTTP 验证。http在这种方式下,Certbot会在你的服务器上创建一个特定的文件,并通过Web服务器使该文件可通过互联网访问。dns需要在你的域名DNS配置中添加一条TXT记录,包含由Let’s Encrypt提供的特定值。ACME服务器将检查这条TXT记录以验证域名的所有权。
- 填写相关选项
- 请求你的电子邮件地址,以便用于接收关于证书续订的重要通知和安全警告。
1
2
3Saving debug log to /var/log/letsencrypt/letsencrypt.log
Enter email address (used for urgent renewal and security notices)
(Enter 'c' to cancel): - 要求你阅读并同意 Let’s Encrypt 的服务条款(Terms of Service)。
1
2
3Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.4-April-3-2024.pdf. You must agree in
order to register with the ACME server. Do you agree? - 询问你是否愿意在首次成功颁发证书后,与电子前哨基金会(Electronic Frontier Foundation, EFF)分享你的电子邮件地址。
1
2
3
4
5Would you be willing, once your first certificate is successfully issued, to
share your email address with the Electronic Frontier Foundation, a founding
partner of the Let's Encrypt project and the non-profit organization that
develops Certbot? We'd like to send you email about our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom. - 询问你希望通过哪种方式验证你对域名的控制权。
How would you like to authenticate with the ACME CA?Spin up a temporary webserver (standalone)- 临时启动一个独立的 Web 服务器来响应 ACME 挑战。Certbot 会在你的机器上运行一个短期的 Web 服务器,并通过 HTTP 请求来完成挑战。这种方式适合于你的主 Web 服务器暂时不可用或者你不想修改现有 Web 服务器配置的情况。
- 选择这个选项时,请确保端口 80(HTTP)没有被其他服务占用,因为 Certbot 需要短暂地接管该端口以完成验证过程。
Place files in webroot directory (webroot)- 使用这种方法,你需要指定 Web 根目录的位置,Certbot 会在该目录下创建特定的文件,这些文件可通过 HTTP 访问路径进行访问,从而完成验证。这是比较常用的方法,特别是当你已经有一个正在运行的 Web 服务器并且不想中断服务的时候。
- 你需要使用 -w 参数指定 Web 根目录,例如 -w /var/www/html,并使用 -d 参数指定需要验证的域名。
- 请求你的电子邮件地址,以便用于接收关于证书续订的重要通知和安全警告。
- 手动验证域名-Http验证
- 创建一个文件,该文件仅包含提供的数据,并将此文件放置在你的Web服务器上的特定URL位置。
1
2
3
4
5
6
7Create a file containing just this data:
xbP5jPl0lCcHk9CwIuMHErNgzZLO7gkZW0qkx9eebu8.Hyfc0w7fKRo-pnunS5a6lVlFTD-ndUcDOpe0DOXJWmc
And make it available on your web server at this URL:
http://exwckv.top/.well-known/acme-challenge/xbP5jPl0lCcHk9CwIuMHErNgzZLO7gkZW0qkx9eebu8.well-known/acme-challenge/xbP5jPl0lCcHk9CwIuMHErNgzZLO7gkZW0qkx9eebu8Web 服务器根目录下文件夹地址- 在文件夹下创建
index.html然后写入xbP5jPl0lCcHk9CwIuMHErNgzZLO7gkZW0qkx9eebu8.Hyfc0w7fKRo-pnunS5a6lVlFTD-ndUcDOpe0DOXJWmc - 访问
http://exwckv.top/.well-known/acme-challenge/xbP5jPl0lCcHk9CwIuMHErNgzZLO7gkZW0qkx9eebu8查看是否正确显示写入内容。
- 创建一个文件,该文件仅包含提供的数据,并将此文件放置在你的Web服务器上的特定URL位置。
- DNS验证
- 部署一个DNS TXT记录以完成验证。域名解析
1
2
3
4
5
6
7
8
9
10
11
12
13
14Please deploy a DNS TXT record under the name:
_acme-challenge.exwckv.top.
with the following value:
gMM67dcK2mpFtof3MQmCpCFkw8V60PEK1ehknKH8BD8
Before continuing, verify the TXT record has been deployed. Depending on the DNS
provider, this may take some time, from a few seconds to multiple minutes. You can
check if it has finished deploying with aid of online tools, such as the Google
Admin Toolbox: https://toolbox.googleapps.com/apps/dig/#TXT/_acme-challenge.exwckv.top.
Look for one or more bolded line(s) below the line ';ANSWER'. It should show the
value(s) you've just added. - 登录域名控制台,设置
_acme-challenge.exwckv.top域名,记录类型为TXT,记录值为gMM67dcK2mpFtof3MQmCpCFkw8V60PEK1ehknKH8BD8
- 部署一个DNS TXT记录以完成验证。域名解析
自己生成证书
自签名证书不被信任,仅限于开发/内部使用,使用时记得手动
openssl version安装检查OpenSSLopenssl genpkey -algorithm RSA -out private.key -aes256生成私钥,用于签署证书-aes256加密(测试情况建议不加)openssl req -new -key private.key -out certificate.csr生成证书请求文件-config ./openssl.cnf使用Openssl配置文件openssl x509 -req -days 365 -in certificate.csr -signkey private.key -out certificate.crt生成证书文件
Openssl配置文件
openssl.cnf
1 | [ req ] |