eugene-khyst / letsencrypt-docker-compose

Set up Nginx and Let’s Encrypt in less than 3 minutes with a Docker Compose project that automatically obtains and renews free Let's Encrypt SSL/TLS certificates and sets up HTTPS in Nginx for multiple domain names. Configuration is done using a simple CLI tool.
Apache License 2.0
473 stars 218 forks source link

CertBot can't handle multiple domains #55

Closed BGarber42 closed 1 year ago

BGarber42 commented 1 year ago

The wrapper script seems to mash domains together given that the output of the jq call includes newlines, which you can't just feed into a shell array.

? Are the entered data correct? Yes
Writing config ./config.json
Compiling template ./templates/nginx.conf.hbs
Compiling template ./templates/servers.conf.hbs
Writing ./nginx-conf/nginx.conf
Writing ./nginx-conf/conf.d/domaina.com.conf
Writing ./nginx-conf/conf.d/siteb.org.conf
Executing command: docker compose exec --no-TTY nginx /letsencrypt-docker-compose/config-nginx.sh
2023/07/01 20:49:32 [notice] 2415#2415: signal process started

Configuring domains:
domaina.com
siteb.org
siteb.org
Configuring domain domaina.com
Switching Nginx to use Let's Encrypt certificate for domaina.com
Configuring domain siteb.org
Switching Nginx to use dummy certificate for siteb.org
Configuring domain siteb.org
Switching Nginx to use dummy certificate for siteb.org
Reloading Nginx configuration

Executing command: docker compose exec --no-TTY certbot /letsencrypt-docker-compose/certbot-certonly.sh
usage:
  certbot [SUBCOMMAND] [options] [-d DOMAIN] [-d DOMAIN] ...

Certbot can obtain and install HTTPS/TLS/SSL certificates.  By default,
it will attempt to use a webserver both for obtaining and installing the
certificate.
certbot: error: argument --rsa-key-size: invalid int value: '4096\n4096'
usage:
  certbot [SUBCOMMAND] [options] [-d DOMAIN] [-d DOMAIN] ...

Certbot can obtain and install HTTPS/TLS/SSL certificates.  By default,
it will attempt to use a webserver both for obtaining and installing the
certificate.
certbot: error: argument --rsa-key-size: invalid int value: '4096\n4096'

Obtaining the certificate for domain domaina.com
Let's Encrypt certificate for domaina.com already exists
Obtaining the certificate for domain siteb.org
Using email example@example.org
example@example.org
RSA key size is 4096
4096
Obtaining the certificate for domain siteb.org
Using email example@example.org
example@example.org
RSA key size is 4096
4096

Executing command: docker compose exec --no-TTY nginx /letsencrypt-docker-compose/config-nginx.sh
2023/07/01 20:49:35 [notice] 2441#2441: signal process started

Configuring domains:
domaina.com
siteb.org
siteb.org
Configuring domain domaina.com
Switching Nginx to use Let's Encrypt certificate for domaina.com
Configuring domain siteb.org
Switching Nginx to use dummy certificate for siteb.org
Configuring domain siteb.org
Switching Nginx to use dummy certificate for siteb.org
Reloading Nginx configuration

Changing the domains line to:

domains=$(jq -r '[.domains[].domain]|join(" ")' $config)

gives a properly output array

eugene-khyst commented 1 year ago

Hi! Thanks for contributing. What OS are you running the tool on? Have you checked the config.json? Does it contain newline (\n) character?

According to the logs, the problem is with the line

rsa_key_size=$(jq -r --arg domain "$domain" '.domains[] | select(.domain == $domain) | .rsaKeySize' $config)
certbot: error: argument --rsa-key-size: invalid int value: '4096\n4096'

Domains were successfully parsed

domains=$(jq -r '.domains[].domain' $config)
Configuring domains:
domaina.com
siteb.org
siteb.org