Skip to content

Commit 33b7d93

Browse files
authored
Merge pull request #550 from buchdag/default-email
Add environment variable for global default email.
2 parents 4febd32 + ba8ae0f commit 33b7d93

File tree

5 files changed

+37
-8
lines changed

5 files changed

+37
-8
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,14 @@ $ docker run --detach \
6565
--name nginx-proxy-letsencrypt \
6666
--volumes-from nginx-proxy \
6767
--volume /var/run/docker.sock:/var/run/docker.sock:ro \
68+
6869
jrcs/letsencrypt-nginx-proxy-companion
6970
```
7071

7172
The host docker socket has to be bound inside this container too, this time to `/var/run/docker.sock`.
7273

74+
Albeit **optional**, it is **recommended** to provide a valid default email address through the `DEFAULT_EMAIL` environment variable, so that Let's Encrypt can warn you about expiring certificates and allow you to recover your account.
75+
7376
### Step 3 - proxyed container(s)
7477

7578
Once both **nginx-proxy** and **letsencrypt-nginx-proxy-companion** containers are up and running, start any container you want proxyed with environment variables `VIRTUAL_HOST` and `LETSENCRYPT_HOST` both set to the domain(s) your proxyed container is going to use.
@@ -83,12 +86,9 @@ $ docker run --detach \
8386
--name your-proxyed-app \
8487
--env "VIRTUAL_HOST=subdomain.yourdomain.tld" \
8588
--env "LETSENCRYPT_HOST=subdomain.yourdomain.tld" \
86-
8789
nginx
8890
```
8991

90-
Albeit **optional**, it is **recommended** to provide a valid email address through the `LETSENCRYPT_EMAIL` environment variable, so that Let's Encrypt can warn you about expiring certificates and allow you to recover your account.
91-
9292
The containers being proxied must expose the port to be proxied, either by using the `EXPOSE` directive in their Dockerfile or by using the `--expose` flag to `docker run` or `docker create`.
9393

9494
If the proxyed container listen on and expose another port than the default `80`, you can force **nginx-proxy** to use this port with the [`VIRTUAL_PORT`](https://github.com/jwilder/nginx-proxy#multiple-ports) environment variable.

app/letsencrypt_service

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,13 @@ function update_certs {
142142

143143
params_d_str=""
144144

145+
# Use container's LETSENCRYPT_EMAIL if set, fallback to DEFAULT_EMAIL
145146
email_varname="LETSENCRYPT_${cid}_EMAIL"
146147
email_address="${!email_varname}"
147148
if [[ "$email_address" != "<no value>" ]]; then
148149
params_d_str+=" --email $email_address"
150+
elif [[ -n "${DEFAULT_EMAIL:-}" ]]; then
151+
params_d_str+=" --email $DEFAULT_EMAIL"
149152
fi
150153

151154
keysize_varname="LETSENCRYPT_${cid}_KEYSIZE"

docs/Advanced-usage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ $ docker run --detach \
6262
--volumes-from nginx-proxy \
6363
--volume /var/run/docker.sock:/var/run/docker.sock:ro \
6464
--env "NGINX_DOCKER_GEN_CONTAINER=nginx-proxy-gen" \
65+
6566
jrcs/letsencrypt-nginx-proxy-companion
6667
```
6768

@@ -74,7 +75,6 @@ $ docker run --detach \
7475
--name your-proxyed-app
7576
--env "VIRTUAL_HOST=subdomain.yourdomain.tld" \
7677
--env "LETSENCRYPT_HOST=subdomain.yourdomain.tld" \
77-
7878
nginx
7979
```
8080

docs/Basic-usage.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,14 @@ $ docker run --detach \
3535
--name nginx-proxy-letsencrypt \
3636
--volumes-from nginx-proxy \
3737
--volume /var/run/docker.sock:/var/run/docker.sock:ro \
38+
3839
jrcs/letsencrypt-nginx-proxy-companion
3940
```
4041

4142
The host docker socket has to be bound inside this container too, this time to `/var/run/docker.sock`.
4243

44+
Albeit **optional**, it is **recommended** to provide a valid default email address through the `DEFAULT_EMAIL` environment variable, so that Let's Encrypt can warn you about expiring certificates and allow you to recover your account.
45+
4346
### Step 3 - proxyed container(s)
4447

4548
Once both **nginx-proxy** and **letsencrypt-nginx-proxy-companion** containers are up and running, start any container you want proxyed with environment variables `VIRTUAL_HOST` and `LETSENCRYPT_HOST` both set to the domain(s) your proxyed container is going to use. Multiple hosts can be separated using commas.
@@ -53,12 +56,9 @@ $ docker run --detach \
5356
--name your-proxyed-app
5457
--env "VIRTUAL_HOST=subdomain.yourdomain.tld" \
5558
--env "LETSENCRYPT_HOST=subdomain.yourdomain.tld" \
56-
5759
nginx
5860
```
5961

60-
Albeit **optional**, it is **recommended** to provide a valid email address through the `LETSENCRYPT_EMAIL` environment variable, so that Let's Encrypt can warn you about expiring certificates and allow you to recover your account.
61-
6262
The containers being proxied must expose the port to be proxied, either by using the `EXPOSE` directive in their Dockerfile or by using the `--expose` flag to `docker run` or `docker create`.
6363

6464
If the proxyed container listen on and expose another port than the default `80`, you can force **nginx-proxy** to use this port with the [`VIRTUAL_PORT`](https://github.com/jwilder/nginx-proxy#multiple-ports) environment variable.

docs/Let's-Encrypt-and-ACME.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,29 @@ The `LETSENCRYPT_MIN_VALIDITY` environment variable can be used to set a differe
1919

2020
#### Contact address
2121

22-
The `LETSENCRYPT_EMAIL` environment variable must be a valid email and will be used by Let's Encrypt to warn you of impeding certificate expiration (should the automated renewal fail) and to recover an account. It is **recommended** to provide a valid contact address using this variable.
22+
The `LETSENCRYPT_EMAIL` environment variable must be a valid email and will be used by Let's Encrypt to warn you of impeding certificate expiration (should the automated renewal fail) and to recover an account. For reasons detailed below, it is **recommended** to provide a default valid contact address for all containers by setting the [`DEFAULT_EMAIL`](#default-contact-address) environment variable on the **letsencrypt_nginx_proxy_companion container**.
23+
24+
**Please note that for each separate [ACME account](#acme-account-keys), only the email provided as a container environment variable at the time of this account creation will be subsequently used. If you don't provide an email address when the account is created, this account will remain without a contact address even if you provide an address in the future.**
25+
26+
Examples:
27+
28+
```bash
29+
$ docker run -d nginx \
30+
VIRTUAL_HOST=somedomain.tld \
31+
LETSENCRYPT_HOST=somedomain.tld \
32+
33+
34+
$ docker run -d nginx \
35+
VIRTUAL_HOST=anotherdomain.tld \
36+
LETSENCRYPT_HOST=anotherdomain.tld \
37+
38+
```
39+
40+
This will result in only the first address being used ([email protected]) and it will be used for **all** future certificates issued with the default ACME account.
41+
42+
This incorrect behaviour is due to a misunderstanding about the way ACME handled contact address(es) when the container was changed to re-use ACME account keys ([more info there](https://github.com/JrCs/docker-letsencrypt-nginx-proxy-companion/issues/510#issuecomment-463256716)) and the fact that `simp_le` is silently discarding the unused addresses. Due to this, it is highly recommended to use the [`DEFAULT_EMAIL`](#default-contact-address) environment variable to avoid unwittingly creating ACME accounts without contact addresses.
43+
44+
If you need to use different contact addresses, you'll need to either use different [ACME account aliases](#multiple-account-keys-per-endpoint) or [disable ACME account keys re-utilization entirely](#disable-account-keys-re-utilization).
2345

2446
#### Private key size
2547

@@ -41,6 +63,10 @@ See the [ACME account keys](#multiple-account-keys-per-endpoint) section.
4163

4264
### global (set on letsencrypt-nginx-proxy-companion container)
4365

66+
#### Default contact address
67+
68+
The `DEFAULT_EMAIL` variable must be a valid email and, when set on the **letsencrypt_nginx_proxy_companion** container, will be used as a fallback when no email address is provided using proxyed container's `LETSENCRYPT_EMAIL` environment variables.
69+
4470
#### Private key re-utilization
4571

4672
The `REUSE_PRIVATE_KEYS` environment variable, when set to `true` on the **letsencrypt-nginx-proxy-companion** container, will set **simp_le** to reuse previously generated private key instead of generating a new one at renewal for all domains.

0 commit comments

Comments
 (0)