Skip to content

Commit d04513f

Browse files
authored
Merge pull request #1 from PabloZaiden/letsencrypt-server-env
Letsencrypt server env
2 parents 81146ba + 69ac4f8 commit d04513f

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

Dockerfile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
FROM openresty/openresty:alpine-fat
22

33
# allowed domains should be lua match pattern
4-
ENV DIFFIE_HELLMAN='' ALLOWED_DOMAINS='.*' AUTO_SSL_VERSION='0.11.1' FORCE_HTTPS='true' SITES=''
4+
ENV DIFFIE_HELLMAN='' ALLOWED_DOMAINS='.*' AUTO_SSL_VERSION='0.11.1' FORCE_HTTPS='true' SITES='' LETSENCRYPT_URL='https://acme-v01.api.letsencrypt.org/directory'
55

66
# Here we install open resty and generate dhparam.pem file.
77
# You can specify DIFFIE_HELLMAN=true to force regeneration of that file on first run
88
# also we create fallback ssl keys
99
RUN apk --no-cache add bash openssl \
10-
&& /usr/local/openresty/luajit/bin/luarocks install lua-resty-auto-ssl $AUTO_SSL_VERSION \
11-
&& openssl req -new -newkey rsa:2048 -days 3650 -nodes -x509 \
10+
&& /usr/local/openresty/luajit/bin/luarocks install lua-resty-auto-ssl $AUTO_SSL_VERSION \
11+
&& openssl req -new -newkey rsa:2048 -days 3650 -nodes -x509 \
1212
-subj '/CN=sni-support-required-for-valid-ssl' \
1313
-keyout /etc/ssl/resty-auto-ssl-fallback.key \
1414
-out /etc/ssl/resty-auto-ssl-fallback.crt \
15-
&& openssl dhparam -out /usr/local/openresty/nginx/conf/dhparam.pem 2048 \
16-
# let's remove default open resty configuration, we'll conditionally add modified version in entrypoint.sh
17-
&& rm /etc/nginx/conf.d/default.conf
15+
&& openssl dhparam -out /usr/local/openresty/nginx/conf/dhparam.pem 2048 \
16+
# let's remove default open resty configuration, we'll conditionally add modified version in entrypoint.sh
17+
&& rm /etc/nginx/conf.d/default.conf
1818

1919
COPY nginx.conf snippets /usr/local/openresty/nginx/conf/
2020
COPY entrypoint.sh /entrypoint.sh

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Available configuration options:
2929
| DIFFIE_HELLMAN | `true` | Force regeneration of `dhparam.pem`. If not specified, default one is used. |
3030
| SITES | `db.com=localhost:5432; *.app.com=localhost:8080`, `_=localhost:8080` | Shortcut for defining multiple proxies, in form of `domain1=endpoint1; domain2=endpoint2`. Default template for proxy is [here](https://github.com/Valian/docker-nginx-auto-ssl/blob/master/snippets/server-proxy.conf). Name `_` means default server, just like in nginx configuration |
3131
| FORCE_HTTPS | `true`, `false` | If `true`, automatically adds location to `resty-server-http.conf` redirecting traffic from http to https. `true` by default. |
32+
| LETSENCRYPT_URL | `https://acme-v01.api.letsencrypt.org/directory`, `https://acme-staging.api.letsencrypt.org/directory` | Let's Encrypt server URL to use |
3233

3334

3435
If you want to proxy multiple sites (probably the most common case, that's why I've made it possible to achieve without custom configuration):

entrypoint.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ if [ "$FORCE_HTTPS" == "true" ]; then
5858
fi
5959

6060

61-
# let's substitute $ALLOWED_DOMAINS into OpenResty configuration
62-
envsubst '$ALLOWED_DOMAINS' \
61+
# let's substitute $ALLOWED_DOMAINS and $LETSENCRYPT_URL into OpenResty configuration
62+
envsubst '$ALLOWED_DOMAINS,$LETSENCRYPT_URL' \
6363
< ${RESTY_CONF_DIR}/resty-http.conf \
6464
> ${RESTY_CONF_DIR}/resty-http.conf.copy \
6565
&& mv ${RESTY_CONF_DIR}/resty-http.conf.copy ${RESTY_CONF_DIR}/resty-http.conf

snippets/resty-http.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ resolver 8.8.8.8;
1919
# Initial setup tasks.
2020
init_by_lua_block {
2121
auto_ssl = (require "resty.auto-ssl").new()
22-
22+
auto_ssl:set("ca", '$LETSENCRYPT_URL')
2323
-- Define a function to determine which SNI domains to automatically handle
2424
-- and register new certificates for. Defaults to not allowing any domains,
2525
-- so this must be configured.

0 commit comments

Comments
 (0)