1、安装certbot(用于自动续约证书)
1.1 添加安装源
sudo add-apt-repository ppa:certbot/certbot
1.2 更新apt安装源
sudo apt-get update
1.3 安装
sudo apt-get install python-certbot-apache
2、安装letsencrypt并生成证书
安装 letsencrypt
sudo apt-get install letsencrypt
生成证书
letsencrypt certonly --agree-tos --email youname@qq.com -d www.xxxxx.com
3、检查/etc/letsencrypt/live/www.xxxxx.com
目录,已经生成证书文件
-
cert.pem: 你不用关心 (这个实际上是服务器证书文件)
-
chain.pem: 你不用关心 (这个实际上是… 自己看文档吧, 我没读懂. 貌似是个递归查找用的链式证书)
-
fullchain.pem: cert.pem + chain.pem 的合体. 需要配置到 nginx 配置文件中的 ssl_certificate .
-
privkey.pem: 私钥. 需要配置到 nginx 配置文件中的 ssl_certificate_key .
server {
listen 443 ssl http2;
# listen [::]:443 ssl http2;
server_name www.gabin.top;
# certs sent to the client in SERVER HELLO are concatenated in ssl_certificate
ssl_certificate /etc/letsencrypt/live/www.xxxxx.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/www.xxxxx.com/privkey.pem;
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets off;
}
续期
sudo letsencrypt renew