如何免费启用https

建站 刘宇帅 5年前 阅读量: 1212

正如大家所看本站使用了https,这篇文章就来讲下如何免费为自己的站点添加https支持。 Let's Encrypt是一个提供免费https证书的认证机构,而Certbot是遵循其协议的客户端程序。而本站就是使用的Certbot Let's Encrypt的维基词条

Let's Encrypt是一个于2015年三季度推出的数字证书认证机构,旨在以自动化流程消除手动创建和安装证书的复杂流程,并推广使万维网服务器的加密连接无所不在,为安全网站提供免费的SSL/TLS证书。 Let\'s Encrypt由互联网安全研究小组(缩写ISRG)提供服务。主要赞助商包括电子前哨基金会、Mozilla基金会、Akamai以及思科。2015年4月9日,ISRG与Linux基金会宣布合作。 用以实现新的数字证书认证机构的协议被称为自动证书管理环境(ACME)。Let's Encrypt宣称这一过程将十分简单、自动化并且免费。 2015年6月,Let's Encrypt得到了一个存储在硬件安全模块中的离线的RSA根证书。这个由IdenTrust证书签发机构交叉签名的根证书,被用于签署两个证书。其中一个就是用于签发请求的证书,另一个则是保存在本地的证书,这个证书用于在上一个证书出问题时作备份证书之用。因为IdenTrust的CA根证书目前已被预置于主流浏览器中,所以Let's Encrypt签发的证书可以从项目开始时就被识别并接受,甚至在用户的浏览器中没有信任ISRG的根证书时也没问题[15]。为了解决对Windows XP的兼容性,目前Let's Encrypt已经获取了另外两个根证书,原来的证书作为备用。

具体操作

  1. 打开Certbot官方下载地址https://certbot.eff.org/, 并根据页面上提示选择对应的系统下载相应的Certbot客户端
  2. 为下载的客户端添加可执行权限
    chmod a+x certbot-auto
  3. 生成证书

    • 生成泛域名证书
      ./certbot-auto --server https://acme-v02.api.letsencrypt.org/directory -d "*.你的域名.com" --manual --preferred-challenges dns-01 certonly
    • 生成特定域名证书
      ./certbot-auto certonly --webroot -w /paht/to/save/certificate -d  www.你的域名.com
  4. 配置nginx https配置
    server {
    listen      443 ssl;
    ssl_certificate /etc/letsencrypt/live/lfuture.cc/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/lfuture.cc/privkey.pem;
    ……
    ……
    }

    http 80 端口配置

    server {
        listen 80;
        server_name lfuture.cc www.lfuture.cc default_server;
        return 301 https://www.lfuture.cc$request_uri;
    }

    reload nginx

    sudo nginx -s reload
  5. 配置定时更新 Let's Encrypt证书默认有效期是90天,所以我们需要定时更新证书,我们这里使用crontab来做,首先把certbot-auto移入PATH目录里(或者在crontab里配置全路径)。
    我们这里配置每天1点1分来更新证书。
    1 1 * * * certbot-auto renew

    执行上面命令会报以下错误

    Cert is due for renewal, auto-renewing...
    Could not choose appropriate plugin: The manual plugin is not working; there may be problems with your existing configuration.
    The error was: PluginError('An authentication script must be provided with --manual-auth-hook when using the manual plugin non-interactively.',)

    这里是说Certbot在非交互模式下无法确认身份,需要实现一个hook校验,参考Pre and Post Validation Hooks
    由于在证书快要过期之前的一个月,Certbot就会发邮件通知,所以我们也可以在命令行完成更新。

    certbot-auto certonly --manual -d www.lfuture.cc
    nginx -s reload

提示

功能待开通!


暂无评论~