今天开始折腾使用Let’s Encrypt为网站签署HTTPS证书,记录过程如下。
我们的网站是使用CentOS 7上的Nginx接入的。 https://certbot.eff.org/#centosrhel7-nginx这个链接是关于CentOS 7上Nginx的配置说明。
安装certbot
Enable EPEL Repository:
wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -ivh epel-release-latest-7.noarch.rpmyum install certbot生成HTTPS证书
手动生成证书:
certbot certonly --standalone -d example.com
-d参数指定域名,是期望开启https的域名
--standalone表示申请证书时将启动certbot内置的webserver,因此需要先把网站的Nginx停掉- 在申请证书时letsencrypt会做认证,如果多次认证失败会启动Rate-limiting,因此在初期调试生成命令的时候,可以在加上
--test-cert这个参数,表示先在letsencrypt的staging环境进行调试
上面命令生成的证书在/etc/letsencrypt/live/example.com中。
ls /etc/letsencrypt/live/example.com
certbot.log cert.pem chain.pem fullchain.pem privkey.pem README配置nginx
nginx中做如下的配置:
server {
listen 80;
server_name example.com;
rewrite ^(.*)$ https://$host$1 permanent;
}
server {
listen 443 ssl;
server_name example.com;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
location / {
root html;
index index.html index.htm;
}
}证书更新
前面生成的证书有效期为3个月,当快要到期时需要使用certbot renew命令更新证书。
在更新证书时需要先停止nginx,然后输入certbot renew --dry-run模拟更新,如果模拟更新没有问题使用certbot renew更新证书后,再启动nginx进行测试。
在证书到期前let’s encrypt为发提醒邮件,可使用下面的命令更新提醒邮件地址:
certbot register --update-registration --email [email protected]证书查看和删除
查看:
certbot certificates删除:
certbot delete