Let’s Encrypt 官方工具 Certbot 配置 SSL 安全证书
- 获取certbot客户端
wget https://dl.eff.org/certbot-auto
chmod a+x ./certbot-auto
./certbot-auto --help
- 生成证书
./certbot-auto certonly --webroot -w /home/wwwroot/xxx(域名指向的文件夹) -d linuxstory.org(域名)
说明:
证书生成过程中按照指示做,比如输入邮箱什么的,生成成功会出现下面的Congratulations提示告知你证书的位置
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at
/etc/letsencrypt/live/linuxstory.org/fullchain.pem. Your cert
will expire on 2017-02-011. To obtain a new version of the
certificate in the future, simply run Let's Encrypt again.
...
- 配置nginx
在nginx的conf中找到"域名.conf"
#https监听443端口
server
{
listen 443;
ssl on;
server_name www.baidu.com(域名) ;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/xxx(域名指向的文件夹);
ssl_certificate /etc/letsencrypt/live/域名/fullchain.pem(刚才生成的证书);
ssl_certificate_key /etc/letsencrypt/live/域名/privkey.pem(刚才生成的证书);
}
#http监听80端口重定向到https
server
{
listen 80;
server_name 域名;
index index.html index.htm index.php default.html default.htm default.php;
return 301 https://域名;
}
说明:
如果想让http和https共存,两种方式都能访问原域名,那就只需要添加监听443端口就行,原80端口里面的内容不变
如果存在多级域名都要配置https,只需要对每一个域名重复上述操作就可以了
证书更新
./certbot-auto renew
如果想要自动更新,可以使用crontab设置定时任务写脚本自动更新