From b11764dff0addf0de2b32ad959808106b6fc92dd Mon Sep 17 00:00:00 2001 From: andryyy Date: Tue, 16 Feb 2021 16:38:28 +0100 Subject: [PATCH] [Config] Add ADDITIONAL_SERVER_NAMES as optional config to define additional server_name parameters for mailcow UI --- data/conf/nginx/templates/server_name.template | 1 - data/conf/nginx/templates/server_name.template.sh | 1 + docker-compose.yml | 3 ++- generate_config.sh | 10 ++++++++++ update.sh | 11 +++++++++++ 5 files changed, 24 insertions(+), 2 deletions(-) delete mode 100644 data/conf/nginx/templates/server_name.template create mode 100755 data/conf/nginx/templates/server_name.template.sh diff --git a/data/conf/nginx/templates/server_name.template b/data/conf/nginx/templates/server_name.template deleted file mode 100644 index 261a1ece..00000000 --- a/data/conf/nginx/templates/server_name.template +++ /dev/null @@ -1 +0,0 @@ -server_name ${MAILCOW_HOSTNAME} autodiscover.* autoconfig.*; diff --git a/data/conf/nginx/templates/server_name.template.sh b/data/conf/nginx/templates/server_name.template.sh new file mode 100755 index 00000000..291b378f --- /dev/null +++ b/data/conf/nginx/templates/server_name.template.sh @@ -0,0 +1 @@ +echo "server_name ${MAILCOW_HOSTNAME} autodiscover.* autoconfig.* $(echo ${ADDITIONAL_SERVER_NAMES} | tr ',' ' ');" diff --git a/docker-compose.yml b/docker-compose.yml index 680bb0e6..852d4be9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -315,9 +315,9 @@ services: - ${IPV4_NETWORK:-172.22.1}.254 command: /bin/sh -c "envsubst < /etc/nginx/conf.d/templates/listen_plain.template > /etc/nginx/conf.d/listen_plain.active && envsubst < /etc/nginx/conf.d/templates/listen_ssl.template > /etc/nginx/conf.d/listen_ssl.active && - envsubst < /etc/nginx/conf.d/templates/server_name.template > /etc/nginx/conf.d/server_name.active && envsubst < /etc/nginx/conf.d/templates/sogo.template > /etc/nginx/conf.d/sogo.active && . /etc/nginx/conf.d/templates/sogo.auth_request.template.sh > /etc/nginx/conf.d/sogo_proxy_auth.active && + . /etc/nginx/conf.d/templates/server_name.template.sh > /etc/nginx/conf.d/server_name.active && . /etc/nginx/conf.d/templates/sites.template.sh > /etc/nginx/conf.d/sites.active && . /etc/nginx/conf.d/templates/sogo_eas.template.sh > /etc/nginx/conf.d/sogo_eas.active && nginx -qt && @@ -335,6 +335,7 @@ services: - TZ=${TZ} - SKIP_SOGO=${SKIP_SOGO:-n} - ALLOW_ADMIN_EMAIL_LOGIN=${ALLOW_ADMIN_EMAIL_LOGIN:-n} + - ADDITIONAL_SERVER_NAMES=${ADDITIONAL_SERVER_NAMES:-} volumes: - ./data/web:/web:ro,z - ./data/conf/rspamd/dynmaps:/dynmaps:ro,z diff --git a/generate_config.sh b/generate_config.sh index 19cc2ae4..6775c6a9 100755 --- a/generate_config.sh +++ b/generate_config.sh @@ -214,6 +214,16 @@ MAILDIR_GC_TIME=7200 ADDITIONAL_SAN= +# Additional server names for mailcow UI +# +# Specify alternative addresses for the mailcow UI to respond to +# This is useful when you set mail.* as ADDITIONAL_SAN and want to make sure mail.maildomain.com will always point to the mailcow UI. +# If the server name does not match a known site, Nginx decides by best-guess and may redirect users to the wrong web root. +# You can understand this as server_name directive in Nginx. +# Comma separated list without spaces! Example: ADDITIONAL_SERVER_NAMES=a.b.c,d.e.f + +ADDITIONAL_SERVER_NAMES= + # Skip running ACME (acme-mailcow, Let's Encrypt certs) - y/n SKIP_LETS_ENCRYPT=n diff --git a/update.sh b/update.sh index a235e3be..d814f423 100755 --- a/update.sh +++ b/update.sh @@ -221,6 +221,7 @@ CONFIG_ARRAY=( "XMPP_C2S_PORT" "XMPP_S2S_PORT" "XMPP_HTTPS_PORT" + "ADDITIONAL_SERVER_NAMES" ) sed -i --follow-symlinks '$a\' mailcow.conf @@ -410,6 +411,16 @@ for option in ${CONFIG_ARRAY[@]}; do if ! grep -q ${option} mailcow.conf; then echo "XMPP_S2S_PORT=5269" >> mailcow.conf fi + elif [[ ${option} == "ADDITIONAL_SERVER_NAMES" ]]; then + if ! grep -q ${option} mailcow.conf; then + echo '# Additional server names for mailcow UI' >> mailcow.conf + echo '#' >> mailcow.conf + echo '# Specify alternative addresses for the mailcow UI to respond to' >> mailcow.conf + echo '# This is useful when you set mail.* as ADDITIONAL_SAN and want to make sure mail.maildomain.com will always point to the mailcow UI.' >> mailcow.conf + echo '# If the server name does not match a known site, Nginx decides by best-guess and may redirect users to the wrong web root.' >> mailcow.conf + echo '# You can understand this as server_name directive in Nginx.' >> mailcow.conf + echo '# Comma separated list without spaces! Example: ADDITIONAL_SERVER_NAMES=a.b.c,d.e.f' >> mailcow.conf + echo 'ADDITIONAL_SERVER_NAMES=' >> mailcow.conf elif [[ ${option} == "XMPP_HTTPS_PORT" ]]; then if ! grep -q ${option} mailcow.conf; then echo "XMPP_HTTPS_PORT=5443" >> mailcow.conf