Ubuntu20.04
Let’s Encrypt 是一个自动签发 https 证书的免费项目
Certbot 是 Let’s Encrypt 官方推荐的证书生成客户端工具
安装Certbot
apt install certbot
apt update
apt install software-properties-common
add-apt-repository ppa:certbot/certbot
apt update
签发证书
单域名
- standalone 方式: certbot 会自己运行内置的web server 来进行验证。
- webroot 方式: certbot 会利用既有的 web server,在其 web root目录下创建隐藏文件, Let’s Encrypt 服务端会通过域名来访问这些隐藏文件,以确认你的确拥有对应域名的控制权。
standalone
certbot 会运行内置web server 来进行验证。
certbot certonly --standalone -d www.domain.com
webroot
certbot 会利用既有的 web server,在其 web root目录下创建隐藏文件, Let’s Encrypt 服务端会通过域名来访问这些隐藏文件,以确认你的确拥有对应域名的控制权。
certbot certonly --webroot -w site_directory -d www.domain.com --agree-tos --email test@163.com
www.domain.com:域名
site_directory:网站目录,例nginx root配置
通配符域名
todo
证书文件说明
`privkey.pem` : the private key for your certificate.
`fullchain.pem`: the certificate file used in most server software.
`chain.pem` : used for OCSP stapling in Nginx >=1.3.7.
`cert.pem` : will break many server configurations, and should not be used
without reading further documentation (see link below).
验证配置
设置Nginx(或其他)服务器的HTTPS配置后,浏览器中访问https://www.domain.com,确认是否成功。
# nginx.conf
server {
listen 443 ssl;
server_name .domain.com;
# 证书文件
ssl_certificate fullchain.pem;
# 秘钥文件
ssl_certificate_key privkey.pem;
# 协议
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
}
证书续订
在证书过期(90天)之前,可以通过运行以下命令来续订。
# 使用 --dry-run 选项表示测试,非真正执行更新
# --cert-name:指定证书
# --force-renewal:强制更新
# certbot renew --cert-name www.***.work --force-renewal
certbot renew