Skip to content

Commit 06a522c

Browse files
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
1 parent 661f61a commit 06a522c

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

templates/web.letsencrypt.ssl.template.yml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ run:
1919
LE_WORKING_DIR="${LETSENCRYPT_DIR}" ./acme.sh --upgrade --auto-upgrade
2020
LE_WORKING_DIR="${LETSENCRYPT_DIR}" ./acme.sh --set-default-ca --server letsencrypt
2121
22+
cat << EOF > /etc/nginx/conf.d/outlets/before-server/20-redirect-http-to-https.conf
23+
server {
24+
listen 80;
25+
26+
location ~ /.well-known {
27+
root /var/www/discourse/public;
28+
allow all;
29+
}
30+
location / {
31+
return 301 https://${DISCOURSE_HOSTNAME}$request_uri;
32+
}
33+
}
34+
EOF
35+
2236
cat << EOF > /etc/nginx/letsencrypt.conf
2337
user www-data;
2438
worker_processes auto;
@@ -41,7 +55,6 @@ run:
4155
4256
server {
4357
listen 80;
44-
listen [::]:80;
4558
4659
location ~ /.well-known {
4760
root /var/www/discourse/public;
@@ -51,6 +64,12 @@ run:
5164
}
5265
EOF
5366
67+
if [ -f "/proc/net/if_inet6" ] ; then
68+
sed -i 's/listen 80;/listen 80;\nlisten [::]:80;/g' /etc/nginx/conf.d/outlets/before-server/20-redirect-http-to-https.conf
69+
sed -i 's/listen 80;/listen 80;\nlisten [::]:80;/g' /etc/nginx/letsencrypt.conf
70+
fi
71+
72+
5473
sed -Ei "s/^#?ACCOUNT_EMAIL=.+/ACCOUNT_EMAIL=${LETSENCRYPT_ACCOUNT_EMAIL}/" \
5574
/shared/letsencrypt/account.conf
5675
@@ -71,8 +90,15 @@ run:
7190
LETSENCRYPT_DIR="/shared/letsencrypt"
7291
/usr/sbin/nginx -c /etc/nginx/letsencrypt.conf
7392
93+
extra_domains() {
94+
if [ -n "$DISCOURSE_HOSTNAME_ALIASES" ]; then
95+
domains=$(echo $DISCOURSE_HOSTNAME_ALIASES | sed "s/,/ -d /g")
96+
echo "-d $domains"
97+
fi
98+
}
99+
74100
issue_cert() {
75-
LE_WORKING_DIR="${LETSENCRYPT_DIR}" ${LETSENCRYPT_DIR}/acme.sh --issue $2 -d ${DISCOURSE_HOSTNAME} --keylength $1 -w /var/www/discourse/public
101+
LE_WORKING_DIR="${LETSENCRYPT_DIR}" ${LETSENCRYPT_DIR}/acme.sh --issue $2 -d ${DISCOURSE_HOSTNAME} $(extra_domains) --keylength $1 -w /var/www/discourse/public
76102
}
77103
78104
cert_exists() {

0 commit comments

Comments
 (0)