English |
  • 美国VPS主机推荐
  • |
  • 代购服务
  • |
  • 10美元以下VPS
  • |
  • VPS新手指南/教程
  • |
  • 留言板
  • |
  • 关于
  • | 登录 |

    免费SSL证书Let's Encrypt(certbot)安装使用教程

    2016年07月4日 上午 | 作者:VPS侦探

    letsencrypt

    Let's Encrypt是很火的一个免费SSL证书发行项目,自动化发行证书,证书有90天的有效期。适合个人使用或者临时使用,不用再忍受自签发证书不受浏览器信赖的提示。去年VPS侦探曾经说过Let's Encrypt的使用教程,但是Let's Encrypt已经发布了新的工具certbot,虽然是新的工具,但是生成证书的使用方法和参数是基本一致的,证书续期更简单了。但是目前看certbot在一些老版本的Linux发行版上的兼容性还是有问题的,特别是在CentOS 5上因为python版本过低是无法用的,CentOS 6上需要先安装epel才行,当然也有很多第三方的工具你也可以自己去尝试一下。

    如果使用lnmp1.4,1.5的话都自带了生成SSL的工具,直接执行 lnmp ssl add 添加或者 lnmp vhost add 添加域名时"add ssl certificate"启用并选择letsencrypt。

    安装方法:

    如果是CentOS 6、7,先执行:yum install epel-release

    cd /root/
    wget https://dl.eff.org/certbot-auto --no-check-certificate
    chmod +x ./certbot-auto
    ./certbot-auto -n

    ./certbot-auto -n只是用来安装依赖包的,也可以跳过直接到下面的生成证书的步骤,国内VPS或服务器上使用的话建议先修改为国内的pip源

    单域名生成证书:

    ./certbot-auto certonly --email youemail@vpser.net --agree-tos --no-eff-email --webroot -w /home/wwwroot/www.vpser.net -d www.vpser.net

    多域名单目录生成单证书:(即一个网站多个域名使用同一个证书)

    ./certbot-auto certonly --email youemail@vpser.net --agree-tos --no-eff-email --webroot -w /home/wwwroot/www.vpser.net -d www.vpser.net -d bbs.vpser.net

    多域名多目录生成一个证书:(即一次生成多个域名的一个证书)

    ./certbot-auto certonly --email youemail@vpser.net --agree-tos --no-eff-email --webroot -w /home/wwwroot/www.vpser.net -d www.vpser.net -d bbs.vpser.net -w /home/wwwroot/lnmp.org -d www.lnmp.org -d lnmp.org

    提示

    IMPORTANT NOTES:
    - Congratulations! Your certificate and chain have been saved at
    /etc/letsencrypt/live/www.vpser.net/fullchain.pem. Your cert will
    expire on 2016-10-01. To obtain a new or tweaked version of this
    certificate in the future, simply run certbot-auto again. To
    non-interactively renew *all* of your certificates, run
    "certbot-auto renew"
    - If you like Certbot, please consider supporting our work by:

    Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
    Donating to EFF: https://eff.org/donate-le

    就是生成成功。

    生成的证书会存在:/etc/letsencrypt/live/www.vpser.net/ 目录下

    具体Nginx和Apache的配置可以参考:https://www.vpser.net/build/letsencrypt-free-ssl.html 里的配置文件。

    修改完配置文件切记重启或reload nginx。

    证书续期

    cerrbot的续期比原来的更加简单,因为证书只有90天,所以建议使用crontab进行自动续期:

    crontab 里加上如下规则:0 3 */5 * * /root/certbot-auto renew --disable-hook-validation --renew-hook "/etc/init.d/nginx reload" 这样每5天就会执行一次所有域名的续期操作。当然时间也可以自行进行调整,建议别太频繁,因为他们都有请求次数的限制,如果需要强制更新可以在前面命令上加上 --force-renew 参数。

    注意事项:

    1、因为默认LNMP的虚拟主机里是禁止 . 开头的隐藏文件及目录的,所以访问http://abc.com/.well-known/acme-challenge/**** 这个链接的话返回403错误,所以必须要将对应虚拟主机配置文件里的
    location ~ /\.
    {
    deny all;
    }
    这段配置删掉或注释掉或在这段配置前面加上
    location ~ /.well-known {
    allow all;
    }

    以上配置代码,然后重启nginx。

    2、如果要启用http2的话,建议编辑lnmp.conf,将里面的Nginx_Modules_Options的单引号里加上 --with-openssl=/root/openssl-1.0.2h

    并执行: cd /root && wget -c https://www.openssl.org/source/openssl-1.0.2h.tar.gz && tar zxf openssl-1.0.2h.tar.gz ,然后使用升级脚本 ./upgrade.sh nginx 升级nginx至1.9.5或更高版本。

    3、国内有些用户反映会卡在Installing Python packages...这个地方不动,因为pip的默认源是国外的,国内可能会有点慢,可以执行下面命令来修改pip源为国内的:
    mkdir ~/.pip
    cat > ~/.pip/pip.conf <<EOF
    [global] index-url = https://pypi.doubanio.com/simple/

    [install] trusted-host=pypi.doubanio.com
    EOF

    执行完,再重新运行certbot的命令应该正常安装python的包了。

    有问题可以在本帖或VPS侦探论坛提问。

    VPS侦探论坛邀请码:https://bbs.vpser.net/reg.php?invitecode=41f1ca437cCC9FXe 有效期至:2016-7-8 13:07

    >>转载请注明出处:VPS侦探 本文链接地址:https://www.vpser.net/build/letsencrypt-certbot.html
    VPS侦探推荐:
    遨游主机VultrLinode搬瓦工LOCVPSKVMLAHOSTKVMHostXen80VPS美国VPS主机,国内推荐腾讯云阿里云
    欢迎加入VPS侦探论坛交流:https://bbs.vpser.net

    发表评论

    *必填

    *必填 (不会被公开)

    评论(33条评论)

    1. VPS侦探说道:

      @没有live文件夹, IP解析的对吗?填写的网站目录正确吗,看它去请求验证返回的文件是不对的

    2. 没有live文件夹说道:

      请问下在执行命令:
      单域名生成证书:

      ./certbot-auto certonly xxxxxx

      之后在/etc/letsencrypt/ 目录下并没有生成live等文件夹,目录下就只有 accounts renewal 两个目录

      提示信息为:

      IMPORTANT NOTES:
      - The following errors were reported by the server:

      Domain: http://www.admol.net
      Type: unauthorized
      Detail: Invalid response from
      http://www.xxxxxxxxx.xxx/.well-known/acme-challenge/xxxxx
      "

      <meta http-equiv="X-UA-Compatible" content="IE=edge""

      To fix these errors, please make sure that your domain name was
      entered correctly and the DNS A record(s) for that domain
      contain(s) the right IP address.

      请问下这是为什么呢

    3. VPS侦探说道:

      @偏执者, 没遇到过这个估计可能是被系统kill了,centos上的话安装的依赖包基本上是python python-libs python-devel python-tools python-pip python-virtualenv dialog libffi-devel augeas-libs这些,yum命令装一下就行,还是可在安装包下载安装那边的话估计就是你设置的系统源慢了,再就是还会pip安装一下软件包,国内的话也可以尝试改成一些国内的pip源

    4. 偏执者说道:

      补充一下错误代码
      Creating virtual environment...
      Installing Python packages...
      /root/certbot-auto: line 1147: 14764 Killed "$0" --le-auto-phase2 "$@"

      Connection closed.

    5. 偏执者说道:

      军哥,使用您的教程成功安装部署SSL证书。
      但是在使用您的续期指令 /root/certbot-auto renew 之后,停留在这一步 Installing Python packages... 几个小时都没有任何反应,重复尝试多次均为同样情况,停留到这一步没有任何反应。请问这个问题如何解决?

    6. VPS侦探说道:

      @xiangyudashu, python2.6下支持有问题,这上面没有具体最后的错误信息不好说

    7. xiangyudashu说道:

      军哥 执行完 ./certbot-auto -n
      之后,提示
      WARNING: unable to check for updates.
      Creating virtual environment...
      Installing Python packages...
      Traceback (most recent call last):
      File "/tmp/tmp.7G60uNOf6f/pipstrap.py", line 146, in
      exit(main())
      File "/tmp/tmp.7G60uNOf6f/pipstrap.py", line 130, in main
      for url, digest in PACKAGES]
      File "/tmp/tmp.7G60uNOf6f/pipstrap.py", line 112, in hashed_download
      response = opener().open(url)
      File "/usr/lib/python2.6/urllib2.py", line 391, in open
      response = self._open(req, data)
      File "/usr/lib/python2.6/urllib2.py", line 409, in _open
      '_open', req)
      File "/usr/lib/python2.6/urllib2.py", line 369, in _call_chain
      result = func(*args)
      File "/usr/lib/python2.6/urllib2.py", line 1198, in https_open
      return self.do_open(httplib.HTTPSConnection, req)
      File "/usr/lib/python2.6/urllib2.py", line 1165, in do_open
      raise URLError(err)
      urllib2.URLError:

      这个是怎么个情况?求军哥百忙之中抽空给个解答啊

    8. VPS侦探说道:

      @LisonFan, 这个只是让他来安装依赖包,有这个提示肯定依赖包已经安装好了

    9. LisonFan说道:

      执行完 ./certbot-auto -n
      最后提示如下:
      Missing command line flags. For non-interactive execution, you will need to specify a plugin on the command line. Run with '--help plugins' to see a list of options, and see https://eff.org/letsencrypt-plugins for more detail on what the plugins do and how to use them.

      是什么意思呢?

    10. VPS侦探说道:

      @hjoker, fullchain.pem 中就包含中间证书

    11. hjoker说道:

      按照教程安装了,现在chrome提示不受信任的证书。。。网上查了说是缺少中间证书,求破

    12. VPS侦探说道:

      @Chilsion, 没按要求装epel吧

    13. Chilsion说道:

      CentOS 6.8 nginx环境。执行
      cd /root/
      wget https://dl.eff.org/certbot-auto --no-check-certificate
      chmod +x ./certbot-auto
      ./certbot-auto -n
      后,出现以下错误,请问怎么解决?
      Complete!
      Creating virtual environment...
      Traceback (most recent call last):
      File "/usr/bin/virtualenv", line 2, in
      import virtualenv
      ImportError: No module named virtualenv

    14. VPS侦探说道:

      @邀请码, 文章末尾自己找

    15. 邀请码说道:

      http://bbs.vpser.net/邀请码 是多少啊

    16. 555说道:

      验证码