Let`s Encrypt 是一个免费、自动化、开源的证书签发服务。由公益组织ISRG 提供服务,得到Mozilla、Cisco等众多机构及公司的支持。
想要让你的网站支持https(目前,建议此方法不要用在公司生产环境),首先需要有一个CA机构签发的ssl证书,Let`s Encrypt 就是一个CA机构;Let`s Encrypt 证书签发支持ACME 协议。以下使用官方推荐的证书自动签发工具Certbot来管理证书。
安装证书自动生成工具Certbot
打开官方站点 https://certbot.eff.org/ 选择Web服务器使用的软件及操作系统,即会打开相应的文档,按照文件安装即可。
此处以 Nginx + CentOS 6 为例,做为参考:
# yum install epel-release ## 根据实际情况选择执行。
# yum install certbot -y
# wget https://dl.eff.org/certbot-auto
# chmod a+x certbot-auto
# cp certbot-auto /usr/local/bin/
生成证书
更新依赖包:# certbot-auto -n,国内主机,执行此步时会比较慢,修改pip源会稍快一些,在 ~/.pip/pip.conf 配置文件中增加以下配置
[global]
index-url=https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=pypi.tuna.tsinghua.edu.cn
修改nginx的站点配置:
# let`s encrypt
location ^~ /.well-known/acme-challenge {
root html;
}
执行命令,生成证书:
# certbot-auto certonly –email 123@163.com –agree-tos –webroot -w /opt /nginx/html/ -d www.123.com -d 123.com
123@163.com 为证书关联邮箱;
/opt/nginx/html/ 为站点根目录,即为上一步/.well-known/acme-challenge 指定的root目录;
www.123.com和123.com 为即将要使用https证书的域名。
生成的证书会在目录 /etc/letsencrypt/live/www.123.com/ 下存放。
配置证书自动续期
因证书生成的有效期为3个月,证书需要续期:
# certbot-auto renew -q
-q 代表不输出详细日志。执行此命令,会将即将到期(小于30天)的证书更新续期。
配置crontab自动续期:
0 1 1,15 * * certbot-auto renew -q
第月1号、15号的凌晨1:00执行更新。
Nginx配置支持https
ssl on;
ssl_certificate /etc/letsencrypt/live/www.123.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/www.123.com/privkey.pem;
至此,你的站点就可以使用https进行访问了。
转载请注明:子暃之路 » Let`s Encrypt – 给你的网站加个https安全访问