Skip to content

Commit 7226db3

Browse files
committed
nginx: start TLS only when certs are provided
- remove generation of self-cigned certificates from start script - remove openssl package installation This only causes problems and isn't recommended to do by nginx developers (nginx/docker-nginx#182).
1 parent 96da168 commit 7226db3

File tree

3 files changed

+12
-18
lines changed

3 files changed

+12
-18
lines changed

Dockerfile

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,17 @@ LABEL org.label-schema.url="https://devicehive.com" \
88
org.label-schema.name="devicehive-proxy" \
99
org.label-schema.version="$DH_PROXY_VERSION"
1010

11-
RUN apt-get update && \
12-
apt-get install -y openssl && \
13-
rm -rf /var/lib/apt/lists/*
14-
1511
ADD nginx.conf /etc/nginx/nginx.conf
1612

17-
ADD server.d/ /etc/nginx/server.d/
1813
ADD upstream.d/ /etc/nginx/upstream.d/
1914
ADD location.d/ /etc/nginx/location.d/
15+
ADD server-available/ /etc/nginx/server-available/
2016
ADD upstreams-available/ /etc/nginx/upstreams-available/
2117
ADD locations-available/ /etc/nginx/locations-available/
2218

2319
ADD admin/ /opt/devicehive/admin/
2420

25-
RUN mkdir /etc/nginx/stream.d/
21+
RUN mkdir /etc/nginx/stream.d/ /etc/nginx/server.d/
2622

2723
COPY proxy-start.sh /opt/devicehive/
2824

proxy-start.sh

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,24 @@
33
set -e
44
set -x
55

6-
if [ ! -f /etc/ssl/dhparam.pem ]
6+
if [ -f /etc/ssl/dhparam.pem -a -f /etc/ssl/ssl_certificate -a -f /etc/ssl/ssl_certificate_key ]
77
then
8-
# NOTE: we only need this if we want to support non-PFS ciphers
9-
openssl dhparam -out /etc/ssl/dhparam.pem 2048
10-
fi
11-
12-
if [ ! -f /etc/ssl/ssl_certificate -o ! -f /etc/ssl/ssl_certificate_key ]
13-
then
14-
openssl req -x509 -newkey rsa:2048 -keyout /etc/ssl/ssl_certificate_key -out /etc/ssl/ssl_certificate -days 365 -nodes -subj '/CN=localhost' -sha256
8+
echo "Found TLS certificate and key. Enabling TLS in nginx."
9+
ln -sf /etc/nginx/server-available/ssl-parameters.conf /etc/nginx/server.d/
10+
else
11+
echo "TLS certificate, key or DH parameters file not found. Starting nginx without TLS support."
1512
fi
1613

1714
echo resolver $(awk 'BEGIN{ORS=" "} $1=="nameserver" {print $2}' /etc/resolv.conf) ";" > /etc/nginx/resolvers.conf
1815

1916
# Enable dh_plugin configuration only if dh_plugin resolvable
2017
getent hosts dh_plugin \
21-
&& ln -s /etc/nginx/upstreams-available/plugin_upstream.conf /etc/nginx/upstream.d/plugin_upstream.conf \
22-
&& ln -s /etc/nginx/locations-available/plugin_location.conf /etc/nginx/location.d/plugin_location.conf
18+
&& ln -sf /etc/nginx/upstreams-available/plugin_upstream.conf /etc/nginx/upstream.d/ \
19+
&& ln -sf /etc/nginx/locations-available/plugin_location.conf /etc/nginx/location.d/
2320

2421
# Enable wsproxyext configuration only if wsproxyext resolvable
2522
getent hosts wsproxyext \
26-
&& ln -s /etc/nginx/upstreams-available/wsproxyext.conf /etc/nginx/upstream.d/wsproxyext.conf \
27-
&& ln -s /etc/nginx/locations-available/wsproxyext.conf /etc/nginx/location.d/wsproxyext.conf
23+
&& ln -sf /etc/nginx/upstreams-available/wsproxyext.conf /etc/nginx/upstream.d/ \
24+
&& ln -sf /etc/nginx/locations-available/wsproxyext.conf /etc/nginx/location.d/
2825

2926
nginx

server.d/ssl-parameters.conf renamed to server-available/ssl-parameters.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ ssl_session_cache shared:SSL:50m;
88
ssl_session_tickets off;
99

1010
# Diffie-Hellman parameter for DHE ciphersuites, recommended 2048 bits
11+
# NOTE: we only need this if we want to support non-PFS ciphers
1112
ssl_dhparam /etc/ssl/dhparam.pem;
1213

1314
# intermediate configuration. tweak to your needs.

0 commit comments

Comments
 (0)