Explorar o código

[Config] Add ADDITIONAL_SERVER_NAMES as optional config to define additional server_name parameters for mailcow UI

andryyy %!s(int64=4) %!d(string=hai) anos
pai
achega
b11764dff0

+ 0 - 1
data/conf/nginx/templates/server_name.template

@@ -1 +0,0 @@
-server_name ${MAILCOW_HOSTNAME} autodiscover.* autoconfig.*;

+ 1 - 0
data/conf/nginx/templates/server_name.template.sh

@@ -0,0 +1 @@
+echo "server_name ${MAILCOW_HOSTNAME} autodiscover.* autoconfig.* $(echo ${ADDITIONAL_SERVER_NAMES} | tr ',' ' ');"

+ 2 - 1
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

+ 10 - 0
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

+ 11 - 0
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