通过DNS认证来部署Let’s Encrypt

原来是通过http认证的方式来完成ACME 的 Identifier Validation Challenges,但是内网的机器就无法完成这个认证,今天看了下,LE支持dns认证了,所以实践了一下。

首先安装Certbot

然后执行

certbot -d ssl-test.robberphex.com --manual --preferred-challenges dns certonly

对于MacOS用户来说,可以执行certbot –config-dir /usr/local/etc/letsencrypt –logs-dir /usr/local/var/log/letsencrypt –work-dir /usr/local/var/lib/letsencrypt -d ssl-test.robberphex.com –manual –preferred-challenges dns certonly 

  • 需要输入邮箱

  • 同意用户协议

  • 同意记录IP

  • 设置域名的TXT记录


    比如图中,设置_acme-challenge.ssl-test.robberphex.com的TXT记录为x-P6A_dQ4_ggZtPvX_bOUeaY7hSM_IS6o-Gzj3h7LBw,然后回车。

  • 提示证书生成成功


我们来一个最简版的配置:

server {
    listen       8443 ssl;
    server_name  ssl-test.robberphex.com;

    ssl_certificate /usr/local/etc/letsencrypt/live/ssl-test.robberphex.com/fullchain.pem;
    ssl_certificate_key /usr/local/etc/letsencrypt/live/ssl-test.robberphex.com/privkey.pem;

    location / {
        default_type "text/plain";
        return 200 "pong";
    }
}

curl测试(不需要设置DNS):

$ curl -i --resolve ssl-test.robberphex.com:8443:127.0.0.1 https://ssl-test.robberphex.com:8443/
HTTP/1.1 200 OK
Server: nginx/1.10.2
Date: Wed, 14 Dec 2016 07:33:41 GMT
Content-Type: text/plain
Content-Length: 4
Connection: keep-alive

pong

浏览器测试(需要设置DNS或者hosts文件):

证书有效

参考资料 http://serverfault.com/a/812038/239044

Leave a Reply

Your email address will not be published. Required fields are marked *

− 4 = 3