Let’s Encrypt,给自己的博客加https

Share on:

对Let’s Encrypt免费项目早有耳闻,今天终于给自己的博客加上https。

Let’s Encrypt是国外一个公共的免费SSL项目,由 Linux 基金会托管,它的来头不小,由Mozilla、思科、Akamai、IdenTrust和EFF等组织发起,目的就是向网站自动签发和管理免费证书,以便加速互联网由HTTP过渡到HTTPS,目前Facebook等大公司开始加入赞助行列。

Let’s Encrypt已经得了 IdenTrust 的交叉签名,这意味着其证书现在已经可以被Mozilla、Google、Microsoft和Apple等主流的浏览器所信任,你只需要在Web 服务器证书链中配置交叉签名,浏览器客户端会自动处理好其它的一切,Let’s Encrypt安装简单,未来大规模采用可能性非常大。

旧版的安装方式,新版往下拉~
获取证书,非常的简单,但由于国内网络的原因,会比较慢一些

git clone https://github.com/letsencrypt/letsencrypt
cd letsencrypt
#每个-d参数后面跟一个域名,需要申请几个域名的证书就跟几个,需要确认这些域名都解析到当前vps的ip上
./letsencrypt-auto certonly --standalone -d example.com -d www.example.com

完成后会有如下提示:

Congratulations! Your certificate and chain have been saved at
/etc/letsencrypt/live/example.com/fullchain.pem. Your cert will
expire on xxxx-xx-xx. To obtain a new version of the certificate in
the future, simply run Let's Encrypt again.

但过程并非那么顺利,报错了,跟我的屌丝配置内存512M有关~~~

Error: open CFI at the end of file; missing .cfi_endproc directive

解决方法

swapon -s
#如果没有任何输出,则继续
umask 0077 && dd if=/dev/zero of=/.swap.img bs=1M count=1024 && mkswap /.swap.img && swapon /.swap.img

这时你的证书就申请好了,去它提示的目录里,fullchain.pem即为证书文件,private.pem即为私钥

注意:申请到的证书有效期3个月,到期后需要用如下命令重新续期,建议加到crontab里面

./letsencrypt-auto renew

然而新版的安装方式更上述有些不同(certbot)

wget https://dl.eff.org/certbot-auto
chmod a+x certbot-auto

#1. 单域名生成证书:
./certbot-auto certonly --email i@zhukun.net --agree-tos --webroot \
-w /home/wwwroot/zhukun.net -d zhukun.net

#2. 多域名单目录生成单证书:(即一个网站多个域名使用同一个证书)
./certbot-auto certonly --email chengyinet@qq.com --agree-tos --webroot -w /home/wwwroot/ifunbox.top -d ifunbox.top -d img.ifunbox.top -d fonts.ifunbox.top -d funboxpower.com -d www.funboxpower.com

#3. 多域名多目录生成多个证书:(即一次生成多个域名的多个证书)
./certbot-auto certonly --email i@zhukun.net --agree-tos --webroot -w /home/wwwroot/b.com -d www1.b.com -d www2.b.com -w /home/wwwroot/a.com -d www1.a.com -d www2.a.com

nginx配置也很简单,包含301跳转

server {
listen 80;
server_name example.com www.example.com;
return 301 https://www.example.com$request_uri;
}
server {
listen 443 ssl;
server_name example.com www.example.com;

ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

if ($host != 'www.example.com') {
rewrite ^/(.*)$ https://www.example.com/$1 permanent;
}

........
}

生成证书后要新增一个子域名debug log里面显示MisconfigurationError: At least one of the required ports is already taken

记得先关闭nginx、apache服务

参考
https://www.zhukun.net/archives/8104
https://www.echoteen.com/letsencrypt-nginx-one.html
http://stackoverflow.com/questions/25575756/gentoo-gcc-failed-emerge

闽ICP备12003472号-7