ubuntu安装Let’s Encrypt证书实测

作者:matrix 发布时间:2017 年 1 月 15 日 分类:兼容并蓄 零零星星

Let’s Encrypt证书出来已经有很长时间,之前用主机未到期,也就干瞪眼。
现在手上拿了一台有设备,其实算下来价格也都差不多,国外的速度是慢点,但是好处很多。

测试环境:
ubuntu 14 64bit
lnmp 1.3

获取证书

git clone https://github.com/letsencrypt/letsencrypt 
cd letsencrypt
./letsencrypt-auto certonly --standalone --email hhtjim@foxmail.com -d hhtjim.com -d www.hhtjim.com
# 若服务器已经占用80端口开启webserver则只需执行webroot:
#  ./letsencrypt-auto certonly --webroot --email hhtjim@foxmail.com -d link.hhtjim.com

执行完上面三个命令之后会有图形界面出现
gui图形界面
选择Agree之后出现这个也就完成了证书的获取

安装证书

修改域名对应下的nginx配置
进入/usr/local/nginx/conf/vhost目录找到和域名同名的conf文件
在server代码块中添加:

listen 443 ssl;
        #listen [::]:80;
        ssl on;
        ssl_certificate /etc/letsencrypt/live/域名/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/域名/privkey.pem;

参考如下完整配置

server
    {
        listen 80;
        listen 443 ssl;
        #listen [::]:80;
        ssl on;
        ssl_certificate /etc/letsencrypt/live/hhtjim.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/hhtjim.com/privkey.pem;

        server_name hhtjim.com www.hhtjim.com;
        index index.html index.htm index.php default.html default.htm default.php;
        root  /home/wwwroot/hhtjim.com;

        include other.conf;
        #error_page   404   /404.html;
        include enable-php.conf;
        include wordpress.conf;

                if ($http_host !~ "^www.hhtjim.com$"){
                    rewrite  ^(.*)    https://www.hhtjim.com$1 permanent;
                }
                if ($scheme = "http"){ 
                        rewrite ^(.*)$  https://$host$1 permanent;
                }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /\.
        {
            deny all;
        }

        access_log  /home/wwwlogs/hhtjim.com.log;
    }

接着准备重启nginx:lnmp nginx restart

参考:loazuo

更新操作

按照网上大多执行的命令我这里就会出现交互界面,需要手动选择webroot目录

How would you like to authenticate with the ACME CA? 

       x x          1  Place files in webroot directory (webroot)           x x  
       x x          2  Spin up a temporary webserver (standalone)  


还好找到办法,只需要添加参数 --webroot -w 设置好存放web路径即可。最终参考如下

ubuntu下保存为sh文件。记得附加x执行权限。然后执行该sh文件即可自动更新证书.

#!/bin/sh
~/letsencrypt/letsencrypt-auto certonly --webroot -w /home/wwwroot/www.hhtjim.com/ --renew-by-default --email hhtjim@foxmail.com -d hhtjim.com -d www.hhtjim.com && lnmp nginx restart

若报错Failed authorization procedure...则需要修改-w参数为网站根目录
如:

-w /home/wwwroot/hhtjim.com/

且nginx配置中将.well-known加入白名单:

location ~ /.well-known {
            allow all;
    }

参考:
http://letsencrypt.readthedocs.io/en/latest/using.html
https://www.ubock.com/article/25
https://stackoverflow.com/questions/42269107/using-certbot-to-apply-lets-encrypt-certificate-failed-authorization-procedure

最后的定时执行

修改定时任务 crontab -e
0 0 1 * * /root/updateLetsEncrypt.sh #每月1号执行sh脚本

重启定时服务 /etc/init.d/cron restart

peace

Let’s Encrypt 项目提供免费的SSl证书

作者:matrix 发布时间:2015 年 9 月 15 日 分类:兼容并蓄 零零星星

官网:https://letsencrypt.org
github: https://github.com/letsencrypt/letsencrypt
letsencrypt

这将表示如果一个网站只是需要最基本的HTTPS加密,那么将无需任何花费购买SSL证书。

Mozilla、思科、Akamai、IdenTrust、EFF 和密歇根大学研究人员宣布了 Let’s Encrypt CA项目,计划为网站提供免费 ssl 证书,加速将 Web 从 HTTP 过渡到 https

上个月才看到了这个消息,大咖阵容提供的公益项目。之前说好的9月份发布,怎么又推迟到了Q4 2015。
网站使用https协议非常不错 。至少比普通网站多了一个绿色的标识,好看还安全~不容易被『挤挨服达不溜』监听到通讯内容。
BUT网站使用https协议必须要有ssl证书,大多都是收费的。不过目前也有免费的,沃通、CloudFlare。。。。。

沃通这些没用过,看到有这么好的公益项目那当然是首推!!值得等待。

Postscript:百度在前几个月都默默启用了全站SSL

阅读剩余部分 »