Skip to content

Commit ae4887a

Browse files
letsencrypt updates: renew location for .well-known, add support for multiple hostnames (#992)
* FEATURE: add DISCOURSE_HOSTNAME_ALIASES add comma-separated DISCOURSE_HOSTNAME_ALIASES to handle multiple aliases for letsencrypt domain generation over env vars FIX: add letsencrypt renew location for .well-known and allow for multi-domain renewal Add /.well-known location in /var/www/discourse/public. Allow .well-known on http to continue to serve traffic without redirects Allows for letsencrypt cert renewals to work properly. With DISCOURSE_HOSTNAME of example.com... multiple domains are not able to renew if they cannot access such as http://alternate.example.com ...which redirects under the current https config. FIX: better listening for ipv6 for ipv4 only Current letsencrypt assumes ipv6 in config. Check for ipv6 before listening * remove commented multi_accept line * Bundle well-known location http passthrough into base ssl template. * Always configure to listen on ipv4 and v6
1 parent a60c564 commit ae4887a

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

templates/web.letsencrypt.ssl.template.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ run:
2626
2727
events {
2828
worker_connections 768;
29-
# multi_accept on;
3029
}
3130
3231
http {
@@ -71,8 +70,15 @@ run:
7170
LETSENCRYPT_DIR="/shared/letsencrypt"
7271
/usr/sbin/nginx -c /etc/nginx/letsencrypt.conf
7372
73+
extra_domains() {
74+
if [ -n "$DISCOURSE_HOSTNAME_ALIASES" ]; then
75+
domains=$(echo $DISCOURSE_HOSTNAME_ALIASES | sed "s/,/ -d /g")
76+
echo "-d $domains"
77+
fi
78+
}
79+
7480
issue_cert() {
75-
LE_WORKING_DIR="${LETSENCRYPT_DIR}" ${LETSENCRYPT_DIR}/acme.sh --issue $2 -d ${DISCOURSE_HOSTNAME} --keylength $1 -w /var/www/discourse/public
81+
LE_WORKING_DIR="${LETSENCRYPT_DIR}" ${LETSENCRYPT_DIR}/acme.sh --issue $2 -d ${DISCOURSE_HOSTNAME} $(extra_domains) --keylength $1 -w /var/www/discourse/public
7682
}
7783
7884
cert_exists() {

templates/web.ssl.template.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ run:
2727
cat << EOF > /etc/nginx/conf.d/outlets/before-server/20-redirect-http-to-https.conf
2828
server {
2929
listen 80;
30+
listen [::]:80;
31+
32+
location ~ /.well-known {
33+
root /var/www/discourse/public;
34+
allow all;
35+
}
36+
3037
return 301 https://${DISCOURSE_HOSTNAME}$request_uri;
3138
}
3239
EOF
@@ -35,6 +42,7 @@ run:
3542
3643
cat << EOF > /etc/nginx/conf.d/outlets/server/20-https.conf
3744
listen 443 ssl;
45+
listen [::]:443 ssl;
3846
http2 on;
3947
4048
ssl_protocols TLSv1.2 TLSv1.3;
@@ -58,8 +66,3 @@ run:
5866
cat << EOF > /etc/nginx/conf.d/outlets/discourse/20-https.conf
5967
add_header Strict-Transport-Security 'max-age=31536000';
6068
EOF
61-
62-
if [ -f "/proc/net/if_inet6" ] ; then
63-
sed -i 's/listen 80;/listen 80;\nlisten [::]:80;/g' /etc/nginx/conf.d/outlets/before-server/20-redirect-http-to-https.conf
64-
sed -i 's/listen 443 ssl;/listen 443 ssl;\nlisten [::]:443 ssl;/g' /etc/nginx/conf.d/outlets/server/20-https.conf
65-
fi

0 commit comments

Comments
 (0)