【问题标题】:Using certbot/lets-encrypt with DNS load balancing?将 certbot/lets-encrypt 与 DNS 负载平衡一起使用?
【发布时间】:2017-03-08 23:31:41
【问题描述】:

我正在为我的网站创建多个 Droplet(按负载缩放),所以我的 DNS 看起来像这样:

www.somesite.com   A    1.2.3.4
www.somesite.com   A    6.7.8.9

是否甚至可以为多个 IP 获得同一域的证书?

我正在使用 certbot --apache --email=admin@domain -d www.domain 安装我的证书,但在第二个 droplet 之后它失败了。

附注我知道 DO 提供了一个负载平衡器,但我现在不能使用它

【问题讨论】:

    标签: ssl ssl-certificate digital-ocean lets-encrypt certbot


    【解决方案1】:

    假设您在负载平衡器 ab 后面有两台服务器,并且服务器终止 SSL。

    假设服务器正在运行支持代理请求到另一台服务器的 NGINX(我想 Apache 也可以处理这个问题,但无法确认)。

    假设您不控制服务器提供的域的 DNS(也许您正在运行 SaaS 并允许用户在您的服务上使用他们自己的域)。

    以下是我们在Lickstats 使用的步骤,以在DigitalOcean load balancers 背后实现这一目标。

    第 1 步。a 上安装 certbot

    第 2 步。b 上配置 NGINX 以将 Let's Encrypt 验证请求代理到 a

    以下设置使用Proxy Protocol,因此我们需要在a 上使用bind NGINX to another port

    server {
        listen 80 proxy_protocol;
        listen 443 proxy_protocol ssl;
    
        server_name example.com www.example.com;
    
        ...
    
        location ^~ /.well-known/acme-challenge {
            proxy_pass http://a.example.com:8080;
        }
    
        ...
    
        ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    }
    

    第 3 步。 使用 webroot 插件获取证书(此操作方法可能使用 apache 插件,但我建议使用较少的自动化来进行负载平衡器后面的精细设置)。

    certbot -d example.com -d www.example.com --webroot --webroot-path /path/to/public/folder certonly
    

    第 4 步。 以 root 身份使用 rsync 将证书同步到 b

    #! /bin/bash
    
    if [ "$(id -u)" != "0" ]; then
        echo "This script must be run as root"
        exit 1
    fi
    
    declare -a files=("/etc/letsencrypt/live" "/etc/nginx/nginx.conf" "/etc/nginx/sites-available")
    for file in "${files[@]}"; do
        rsync -axLS --delete $file admin@b.example.com:sync
    done
    
    echo "Done"
    

    第 5 步。 以 root 身份使用 rsyncb 上应用证书。

    #! /bin/bash
    
    if [ "$(id -u)" != "0" ]; then
        echo "This script must be run as root"
        exit 1
    fi
    
    data="/home/admin/sync"
    
    if [ ! -d $data ]; then
        echo "$data folder not found"
        exit 1
    fi
    
    rsync -axS --delete $data/live/ /etc/letsencrypt/live
    rsync -axS --delete $data/nginx.conf /etc/nginx/nginx.conf
    rsync -axS --delete $data/sites-available/ /etc/nginx/sites-available
    
    chown -R root:root /etc/letsencrypt/live
    chown -R root:root /etc/nginx/nginx.conf
    chown -R root:root /etc/nginx/sites-available
    
    if nginx-ensites.sh; then
        rm -r $data
        echo "Done"
    fi
    

    第 6 步。 通过创建指向 sites-enabled 的符号链接来启用 sites-available 中的网站。

    #!/bin/bash
    
    if [ "$(id -u)" != "0" ]; then
        echo "This script must be run as root"
        exit 1
    fi
    
    nginx=/usr/sbin/nginx
    
    rm /etc/nginx/sites-enabled/*
    
    files=( /etc/nginx/sites-available/* )
    for file in "${files[@]}"
    do
        src=../sites-available/${file##*/}
        dest=/etc/nginx/sites-enabled/${file##*/}
        if [ ! -f $dest ]; then
            ln -s $src $dest
        fi
    done
    
    if $nginx -t; then
        $nginx -s reload
        echo "All available sites have been enabled"
    fi
    

    第 7 步。使用 cron 作业每月尝试更新一次。

    【讨论】:

    • 我想没有直接的方法可以做到这一点。我担心最终的解决方案可能需要做这种工作和复制证书。感谢您将所有内容放在一起并分享实现!
    • 这是一个很好的答案!
    • Apache 无法处理。像在 nginx 中那样做的方法是代理平衡器指令,但是 LE 放弃得太早了,因为 Apache 只有 lbmethods 失败,404 到 LE-end。每添加一个 blanacer 组节点,情况就会变得更糟。它应该有 lbmethod keep-trying-all-nodes-until-succeed - 但它没有。
    【解决方案2】:

    挑战tls-sni-01http-01 将不起作用,因为您无法预测letsencrypt 请求将到达的服务器。

    您可以在单个服务器上使用 DNS 质询,然后在另一台服务器上同步生成的证书。

    使用certbot,可以使用命令行--preferred-challenges dns,然后将TXT条目添加到域中。

    【讨论】:

      【解决方案3】:

      这听起来像是一个 certbot 限制。大概您有办法将您的网站部署到这些多个 IP;现在使用相同的方式将挑战部署到这些多个 IP。没关系,如果需要一个小时,LE是有耐心的。 certbot 是否可以帮助您,我不知道,但还有很多其他 Let's Encrypt 客户端。

      正如另一个答案所说,dns-01 在这里最简单,假设您可以自动更改 DNS。

      【讨论】:

        猜你喜欢
        • 2017-04-28
        • 1970-01-01
        • 2016-09-11
        • 1970-01-01
        • 2015-02-11
        • 2021-09-06
        • 2018-08-20
        • 2017-08-13
        • 2010-09-15
        相关资源
        最近更新 更多