Skip to content

Commit

Permalink
Merge pull request #253 from yanokwa/fix-renewal-bug
Browse files Browse the repository at this point in the history
Fix LetsEncrypt renewal failures
  • Loading branch information
matthew-white authored Nov 5, 2021
2 parents 325da23 + cd4ee5d commit 206955a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 10 deletions.
13 changes: 13 additions & 0 deletions files/nginx/certbot.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
server {
# Listen only on port 81 for localhost, and nothing else.
server_name 127.0.0.1;
listen 127.0.0.1:81 default_server;

charset utf-8;

# Certbot's folder used for the ACME challenge response.
location ^~ /.well-known/acme-challenge {
default_type text/plain;
root /var/www/letsencrypt;
}
}
8 changes: 6 additions & 2 deletions files/nginx/odk-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,20 @@ CNAME=$([ "$SSL_TYPE" = "customssl" ] && echo "local" || echo "$DOMAIN") \
if [ "$SSL_TYPE" = "letsencrypt" ]
then
echo "starting nginx with certbot.."
cp /usr/share/nginx/certbot.conf /etc/nginx/conf.d/certbot.conf
cp /usr/share/nginx/redirector.conf /etc/nginx/conf.d/redirector.conf
/bin/bash /scripts/start_nginx_certbot.sh
elif [ "$SSL_TYPE" = "upstream" ]
then
echo "starting nginx without local SSL to allow for upstream SSL.."
perl -i -ne 's/listen 443.*/listen 80;/; print if ! /ssl_/' /etc/nginx/conf.d/odk.conf
perl -i -pe 's/X-Forwarded-Proto \$scheme/X-Forwarded-Proto https/;' /etc/nginx/conf.d/odk.conf
rm -f /etc/nginx/conf.d/certbot.conf
echo "starting nginx without local SSL to allow for upstream SSL.."
rm -f /etc/nginx/conf.d/redirector.conf
nginx -g "daemon off;"
else
echo "starting nginx without certbot.."
rm -f /etc/nginx/conf.d/certbot.conf
rm -f /etc/nginx/conf.d/redirector.conf
nginx -g "daemon off;"
fi

19 changes: 19 additions & 0 deletions files/nginx/redirector.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
server {
# Listen on plain old HTTP and catch all requests so they can be redirected
# to HTTPS instead.
listen 80 default_server reuseport;
listen [::]:80 default_server reuseport;

# Pass this particular URL off to the certbot server so it can properly
# respond to the Let's Encrypt ACME challenges for the HTTPS certificates.
location '/.well-known/acme-challenge' {
default_type "text/plain";
proxy_pass http://localhost:81;
}

# Everything else gets shunted over to HTTPS for each user defined
# server to handle.
location / {
return 301 https://$http_host$request_uri;
}
}
17 changes: 9 additions & 8 deletions nginx.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ COPY ./ ./
RUN files/prebuild/write-version.sh
RUN files/prebuild/build-frontend.sh


FROM jonasal/nginx-certbot:2.4
# make sure you have updated *.conf files when upgrading this
FROM jonasal/nginx-certbot:2.4.1

EXPOSE 80
EXPOSE 443
Expand All @@ -15,14 +15,15 @@ ENTRYPOINT [ "/bin/bash", "/scripts/odk-setup.sh" ]

RUN apt-get update; apt-get install -y openssl netcat nginx-extras lua-zlib

RUN mkdir -p /etc/selfsign/live/local
COPY files/nginx/odk-setup.sh /scripts
RUN mkdir -p /etc/selfsign/live/local/
COPY files/nginx/odk-setup.sh /scripts/

COPY files/local/customssl/*.pem /etc/customssl/live/local/

COPY files/nginx/default /etc/nginx/sites-enabled/
COPY files/nginx/inflate_body.lua /usr/share/nginx
COPY files/nginx/odk.conf.template /usr/share/nginx
COPY --from=intermediate client/dist/ /usr/share/nginx/html
COPY files/nginx/inflate_body.lua /usr/share/nginx/
COPY files/nginx/odk.conf.template /usr/share/nginx/
COPY files/nginx/certbot.conf /usr/share/nginx/
COPY files/nginx/redirector.conf /usr/share/nginx/
COPY --from=intermediate client/dist/ /usr/share/nginx/html/
COPY --from=intermediate /tmp/version.txt /usr/share/nginx/html/

0 comments on commit 206955a

Please sign in to comment.