Centos6下使用ACME创建Letsencrypt证书并保持证书自动更新

Home Forums Share your experiences / 经验分享 Centos6下使用ACME创建Letsencrypt证书并保持证书自动更新

Tagged: ,

Viewing 0 reply threads
  • Author
    Posts
    • Participant
      #1 lightwriter #540435

      ACME.SH项目地址

      https://github.com/Neilpang/acme.sh

      帮助说明

      https://github.com/Neilpang/acme.sh/wiki/%E8%AF%B4%E6%98%8E

      使用acme.sh创建letsencypt非常方便.

      本教程假设你已经在本机上安装配置好了一个WEB服务器.

       

      1. 安装 acme.sh

      curl  https://get.acme.sh | sh

      此时已经安装好, 并自动加入了crontab了, 每天 0:00 点自动检测所有的证书, 如果快过期了, 需要更新, 则会自动更新证书.

       

      2. 生成证书

      cd ./.acme.sh

      注意.acme.sh以.开头,所以隐藏了ll -a才可以看到

      ./acme.sh  –issue  -d domain.com -d http://www.domain.com  –webroot  /data/wwwroot/www.domain.com

      这种方式自动在你的网站根目录下创建一个 .well-known 的文件夹., 来验证你的域名所有权,完成验证. 然后就可以生成证书了.

      证书创建好会提示

      Your cert is in  /root/.acme.sh/domain.com/domain.com.cer

      Your cert key is in  /root/.acme.sh/domain.com/domain.com.key

      The intermediate CA cert is in  /root/.acme.sh/domain.com/ca.cer

      And the full chain certs is there:  /root/.acme.sh/domain.com/fullchain.cer

       

      3. copy/安装 证书

      前面证书生成以后, 接下来需要把证书 copy 到真正需要用它的地方.

      注意, 默认生成的证书都放在安装目录下: ~/.acme.sh/, 请不要直接使用此目录下的文件, 例如: 不要直接让 nginx/apache 的配置文件使用这下面的文件. 这里面的文件都是内部使用, 而且目录结构可能会变化.

      正确的使用方法是使用 –installcert 命令,并指定目标位置, 然后证书文件会被copy到相应的位置, 例如:

       

      ./acme.sh –installcert -d domain.com -d http://www.domain.com  \

      –key-file  /usr/local/nginx/ssl/domain.com/domain.com.key  \

      –fullchain-file /usr/local/nginx/ssl/domain.com/fullchain.cer \

      –reloadcmd “service nginx force-reload”

       

      我们将证书放在/usr/local/nginx/ssl/domain.com/下(要求安装程序将证书COPY到这里)

      要保证/usr/local/nginx/ssl/domain.com/这个目录是存在的,否则会出以下错误

      line 4703: /usr/local/nginx/ssl/domain.com/domain.com.key: No such file or directory

      值得注意的是, 这里指定的所有参数都会被自动记录下来, 并在将来证书自动更新以后, 被再次自动调用.

       

      4,更新一下nginx的conf配置将ssl_certificate, ssl_certificate_key指向正确的证书文件

      vi /usr/local/nginx/conf/vhost/www.domain.com.conf

      ssl_certificate /usr/local/nginx/ssl/domain.com/fullchain.cer;

      ssl_certificate_key /usr/local/nginx/ssl/domain.com/domain.com.key;

      Nginx 的配置 ssl_certificate 使用 /etc/nginx/ssl/fullchain.cer ,而非 /etc/nginx/ssl/domain.cer ,否则 SSL Labs 的测试会报 Chain issues Incomplete 错误。

      重启NGINX,应该就生效了,可以去ssllabs测试一下证书,如果启用了Cloudflare的CDN要关了CDN才可以

       

      5. 更新证书

      已经自动加入到crontab了,不用管

       

      6. 更新 acme.sh

      acme.sh –upgrade

      如果你不想手动升级, 可以开启自动升级:

      acme.sh  –upgrade  –auto-upgrade

      之后, acme.sh 就会自动保持更新了.

      你也可以随时关闭自动更新:

      acme.sh –upgrade  –auto-upgrade  0

Viewing 0 reply threads

You must be logged in to reply to this topic.