使用docker-compose和lemp stack设置letencrypt ssl证书时出现问题

时间:2020-06-04 15:34:05

标签: docker ssl-certificate lets-encrypt

当我尝试按照以下方法获取并设置letencrypt ssl证书的续订时: Nginx and Let’s Encrypt with Docker in Less Than 5 Minute

我收到此消息:


    certbot domains: xxx.heypongo.com
    email: "***@***.com"
    ### Downloading recommended TLS parameters ...
    ### Creating dummy certificate for xxx.heypongo.com ...
    Generating a RSA private key
    ...+++++
    ..+++++
    writing new private key to '/etc/letsencrypt/live/xxx.heypongo.com/privkey.pem'
    -----
    ### Starting nginx ...
    Recreating redis     ... done
    Recreating php_mysql         ... done
    Recreating pongo-echo-server ... done
    Recreating php-pongo         ... done
    ### Deleting dummy certificate for xxx.heypongo.com ...
    ### Requesting Let's Encrypt certificate for xxx.heypongo.com ...
    Saving debug log to /var/log/letsencrypt/letsencrypt.log
    Plugins selected: Authenticator webroot, Installer None
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Would you be willing to share your email address with the Electronic Frontier
    Foundation, a founding partner of the Let's Encrypt project and the non-profit
    organization that develops Certbot? We'd like to send you email about our work
    encrypting the web, EFF news, campaigns, and ways to support digital freedom.
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    (Y)es/(N)o: Y
    Obtaining a new certificate
    Performing the following challenges:
    http-01 challenge for xxx.heypongo.com
    Using the webroot path /var/www/certbot for all unmatched domains.
    Waiting for verification...
    Challenge failed for domain xxx.heypongo.com
    http-01 challenge for xxx.heypongo.com
    Cleaning up challenges
    Some challenges have failed.
    IMPORTANT NOTES:
     - The following errors were reported by the server:
       Domain: xxx.heypongo.com
       Type:   connection
       Detail: Fetching
       http://xxx.heypongo.com/.well-known/acme-challenge/p1ofEC3LyccqQEF-Nc8O73LwgYzsak9tVFWpf4i9ZXA:
       Connection refused
       To fix these errors, please make sure that your domain name was
       entered correctly and the DNS A/AAAA record(s) for that domain
       contain(s) the right IP address. Additionally, please check that
       your computer has a publicly routable IP address and that no
       firewalls are preventing the server from communicating with the
       client. If you're using the webroot plugin, you should also verify
       that you are serving files from the webroot path you provided.
     - Your account credentials have been saved in your Certbot
       configuration directory at /etc/letsencrypt. You should make a
       secure backup of this folder now. This configuration directory will
       also contain certificates and private keys obtained by Certbot so
       making regular backups of this folder is ideal.
     - We were unable to subscribe you the EFF mailing list because your
       e-mail address appears to be invalid. You can try again later by
       visiting https://act.eff.org.

有关信息,这是我的docker-compose文件:


    version: '3.5'
    services:
      #PROD
      php-pongo:
        image: heypongo/php-pongo:${TAG}
        build:
          context: ./
          args:
            PROJECT_NAME: ${COMPOSE_PROJECT_NAME}
          target: php-prod
        container_name: php-pongo
        command: bash -c 'chmod -R 770 /var/pongo/storage/ && chmod -R 770 /var/pongo/public/swagger/ && nginx && php-fpm '
    #    comment the line before and un-comment line after for debug purposes
    #    entrypoint: ["sh", "-c", "echo debug && sleep infinity"]
        ports:
          - 80:80
          - 443:443
        volumes:
          - ./conf/default.prod.conf:/etc/nginx/conf.d/default.conf
          - ./conf/ws.dev.pongo.conf:/etc/nginx/conf.d/ws.dev.pongo.conf
          - ./data/certbot/conf:/etc/letsencrypt
          - ./data/certbot/www:/var/www/certbot
        depends_on:
          - pongo-echo-server
          - php_mysql
        networks:
          - pongo-network
        restart: unless-stopped

      pongo-echo-server:
        image: heypongo/pongo-echo-server:${LARAVEL_ECHO_TAG}
        links:
          - redis
        build:
          context: ./
          dockerfile: ./Dockerfile.echo-server
        container_name: pongo-echo-server
        ports:
          - "6001:6001"
        depends_on:
          - redis
        networks:
          - pongo-network
        restart: unless-stopped

      redis:
        image: redis
        ports:
          - "6379:6379"
        container_name: redis
        command: ["redis-server", "--appendonly", "yes"]
        networks:
          - pongo-network
        restart: unless-stopped

      php_mysql:
        image: "mysql:5.7"
        container_name: php_mysql
        ports:
          - "3309:3306"
        environment:
          - MYSQL_ROOT_PASSWORD=${DB_ROOT_PASSWORD}
          - MYSQL_DATABASE=${DB_DATABASE}
          - MYSQL_USER=${DB_USERNAME}
          - MYSQL_PASSWORD=${DB_PASSWORD}
        networks:
          - pongo-network
        restart: unless-stopped

      certbot:
        image: certbot/certbot
        container_name: certbot
        volumes:
          - ./data/certbot/conf:/etc/letsencrypt
          - ./data/certbot/www:/var/www/certbot
        entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"
        networks:
          - pongo-network
        restart: unless-stopped

    networks:
      pongo-network:

和我的初始化脚本:


    #!/bin/bash

    export $(cat .env | sed 's/#.*//g' | xargs)

    domains=("${DOMAIN_NAME:-xxx.heypongo.com}")
    echo "certbot domains: ${domains[*]}"
    rsa_key_size=4096
    data_path="./data/certbot"
    #email="***@gmail.com"
    email="${CERTBOT_MAIL:-xxx@xxx.com}"
    echo "email: $email"
    staging=0 # Set to 1 if you're testing your setup to avoid hitting request limits

    if [ -d "$data_path" ]; then
      read -p "Existing data found for $domains. Continue and replace existing certificate? (y/N) " decision
      if [ "$decision" != "Y" ] && [ "$decision" != "y" ]; then
        exit 0
      fi
    fi


    if [ ! -e "$data_path/conf/options-ssl-nginx.conf" ] || [ ! -e "$data_path/conf/ssl-dhparams.pem" ]; then
      echo "### Downloading recommended TLS parameters ..."
      mkdir -p "$data_path/conf"
      curl -s https://raw.githubusercontent.com/certbot/certbot/master/certbot-nginx/certbot_nginx/options-ssl-nginx.conf > "$data_path/conf/options-ssl-nginx.conf"
      curl -s https://raw.githubusercontent.com/certbot/certbot/master/certbot/ssl-dhparams.pem > "$data_path/conf/ssl-dhparams.pem"
      pwd "$data_path" && ls -lah "$data_path/conf"
      echo
    fi

    echo "### Creating dummy certificate for $domains ..."
    path="/etc/letsencrypt/live/$domains"
    mkdir -p "$data_path/conf/live/$domains"
      pwd "$data_path" && ls -lah "$data_path/conf/live"
    docker-compose -f docker-compose.prod.yml run --rm --entrypoint "\
      openssl req -x509 -nodes -newkey rsa:1024 -days 1\
        -keyout '$path/privkey.pem' \
        -out '$path/fullchain.pem' \
        -subj '/CN=localhost'" certbot
    echo


    echo "### Starting nginx ..."
    docker-compose -f docker-compose.prod.yml up --force-recreate -d php-pongo
    echo

    echo "### Deleting dummy certificate for $domains ..."
    docker-compose -f docker-compose.prod.yml run --rm --entrypoint "\
      rm -Rf /etc/letsencrypt/live/$domains && \
      rm -Rf /etc/letsencrypt/archive/$domains && \
      rm -Rf /etc/letsencrypt/renewal/$domains.conf" certbot
    echo


    echo "### Requesting Let's Encrypt certificate for $domains ..."
    #Join $domains to -d args
    domain_args=""
    for domain in "${domains[@]}"; do
      domain_args="$domain_args -d $domain"
    done

    echo "domain args : $domain_args"

    # Select appropriate email arg
    case "$email" in
      "") email_arg="--register-unsafely-without-email" ;;
      *) email_arg="--email $email" ;;
    esac

    # Enable staging mode if needed
    if [ $staging != "0" ]; then staging_arg="--staging"; fi

    docker-compose -f docker-compose.prod.yml run --rm --entrypoint "\
      certbot certonly --webroot -w /var/www/certbot \
        $staging_arg \
        $email_arg \
        $domain_args \
        --rsa-key-size $rsa_key_size \
        --agree-tos \
        --force-renewal" certbot
    echo

    echo "### Reloading nginx ..."
    docker-compose -f docker-compose.prod.yml exec php-pongo nginx -s reload

我的dns是A注册的。

我已经花了2天的时间进行这项工作,但我不知道出了什么问题。 任何帮助或提示,我们将不胜感激。 预先感谢。

该项目托管在Digital Ocean VPS(Droplet)上

0 个答案:

没有答案