From eac4d553a92f6c3a80f81476a41af6e5726c7cd7 Mon Sep 17 00:00:00 2001 From: Patrick Georgi Date: Tue, 27 Nov 2018 00:12:12 +0100 Subject: [PATCH 1/7] nginx: Allow extending config with overrides To facilitate this, the default redirect at / can be disabled, even if the default remains at redirecting to the webmailer. The extensions are within the host scope and are read from $ROOT/overrides/nginx/*.conf. --- core/nginx/Dockerfile | 1 + core/nginx/conf/nginx.conf | 8 +++++--- docs/compose/.env | 3 +++ docs/compose/docker-compose.yml | 1 + 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/core/nginx/Dockerfile b/core/nginx/Dockerfile index 7181487e..717cb225 100644 --- a/core/nginx/Dockerfile +++ b/core/nginx/Dockerfile @@ -14,6 +14,7 @@ COPY *.py / EXPOSE 80/tcp 443/tcp 110/tcp 143/tcp 465/tcp 587/tcp 993/tcp 995/tcp 25/tcp 10025/tcp 10143/tcp VOLUME ["/certs"] +VOLUME ["/overrides"] CMD /start.py diff --git a/core/nginx/conf/nginx.conf b/core/nginx/conf/nginx.conf index 17d67526..0bc6cf07 100644 --- a/core/nginx/conf/nginx.conf +++ b/core/nginx/conf/nginx.conf @@ -84,14 +84,16 @@ http { } {% else %} + include /overrides/*.conf; + # Actual logic - {% if WEBMAIL != 'none' %} - {% if WEB_WEBMAIL != '/' %} + {% if WEBROOT_REDIRECT %} location / { - return 301 {{ WEB_WEBMAIL }}; + return 301 {{ WEBROOT_REDIRECT }}; } {% endif %} + {% if WEBMAIL != 'none' %} location {{ WEB_WEBMAIL }} { {% if WEB_WEBMAIL != '/' %} rewrite ^({{ WEB_WEBMAIL }})$ $1/ permanent; diff --git a/docs/compose/.env b/docs/compose/.env index 2100e27a..bd98df31 100644 --- a/docs/compose/.env +++ b/docs/compose/.env @@ -97,6 +97,9 @@ COMPRESSION_LEVEL= # Web settings ################################### +# Path to redirect / to +WEB_DEFAULT=/webmail + # Path to the admin interface if enabled WEB_ADMIN=/admin diff --git a/docs/compose/docker-compose.yml b/docs/compose/docker-compose.yml index b8d15587..72981f81 100644 --- a/docs/compose/docker-compose.yml +++ b/docs/compose/docker-compose.yml @@ -29,6 +29,7 @@ services: - "$BIND_ADDRESS6:587:587" volumes: - "$ROOT/certs:/certs" + - "$ROOT/overrides/nginx:/overrides" redis: image: redis:alpine From 2de4995fec6a586acd0874135da62d6ca50deb71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20M=C3=B6hlmann?= Date: Fri, 7 Dec 2018 15:17:04 +0200 Subject: [PATCH 2/7] Don't redirect when webmail is served on '/' --- core/nginx/conf/nginx.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/nginx/conf/nginx.conf b/core/nginx/conf/nginx.conf index 0bc6cf07..3e605dd2 100644 --- a/core/nginx/conf/nginx.conf +++ b/core/nginx/conf/nginx.conf @@ -87,7 +87,7 @@ http { include /overrides/*.conf; # Actual logic - {% if WEBROOT_REDIRECT %} + {% if WEBROOT_REDIRECT and WEB_WEBMAIL != '/' %} location / { return 301 {{ WEBROOT_REDIRECT }}; } From 9208d7262f1229216688050eada3eb3fa04f787e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20M=C3=B6hlmann?= Date: Fri, 7 Dec 2018 15:22:01 +0200 Subject: [PATCH 3/7] Correct variable naming in .env --- docs/compose/.env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/compose/.env b/docs/compose/.env index bd98df31..5264b91a 100644 --- a/docs/compose/.env +++ b/docs/compose/.env @@ -98,7 +98,7 @@ COMPRESSION_LEVEL= ################################### # Path to redirect / to -WEB_DEFAULT=/webmail +WEBROOT_REDIRECT=/webmail # Path to the admin interface if enabled WEB_ADMIN=/admin From c25ba75d68775c88ae8e9b9019e90c5e6a277b8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20M=C3=B6hlmann?= Date: Fri, 7 Dec 2018 15:29:33 +0200 Subject: [PATCH 4/7] Include WEBROOT_REDIRECT in setup templates --- setup/flavors/compose/docker-compose.yml | 3 ++- setup/flavors/compose/mailu.env | 3 +++ setup/flavors/stack/docker-compose.yml | 3 ++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/setup/flavors/compose/docker-compose.yml b/setup/flavors/compose/docker-compose.yml index 81b6bcb2..1a77b1de 100644 --- a/setup/flavors/compose/docker-compose.yml +++ b/setup/flavors/compose/docker-compose.yml @@ -28,7 +28,8 @@ services: {% endfor %} volumes: - "{{ root }}/certs:/certs" - + - "{{ root }}/overrides/nginx:/overrides" + {% if resolver_enabled %} resolver: image: mailu/unbound:{{ version }} diff --git a/setup/flavors/compose/mailu.env b/setup/flavors/compose/mailu.env index 4a14de63..c7c60fdf 100644 --- a/setup/flavors/compose/mailu.env +++ b/setup/flavors/compose/mailu.env @@ -110,6 +110,9 @@ COMPRESSION_LEVEL={{ compression_level }} # Web settings ################################### +# Path to redirect / to +WEBROOT_REDIRECT=/webmail + # Path to the admin interface if enabled WEB_ADMIN={{ admin_path }} diff --git a/setup/flavors/stack/docker-compose.yml b/setup/flavors/stack/docker-compose.yml index b9537e94..6e471f39 100644 --- a/setup/flavors/stack/docker-compose.yml +++ b/setup/flavors/stack/docker-compose.yml @@ -26,9 +26,10 @@ services: {% endfor %} volumes: - "{{ root }}/certs:/certs" + - "{{ root }}/overrides/nginx:/overrides" deploy: replicas: 1 - + {% if resolver_enabled %} resolver: image: mailu/unbound:{{ version }} From 20f1faf6d03ee285ef21bf8e089815474a11f85c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20M=C3=B6hlmann?= Date: Fri, 7 Dec 2018 16:10:52 +0200 Subject: [PATCH 5/7] Send 404 when nothing server at '/' Prevents Nginx welcome screen --- core/nginx/conf/nginx.conf | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/nginx/conf/nginx.conf b/core/nginx/conf/nginx.conf index 3e605dd2..a169cd75 100644 --- a/core/nginx/conf/nginx.conf +++ b/core/nginx/conf/nginx.conf @@ -91,6 +91,8 @@ http { location / { return 301 {{ WEBROOT_REDIRECT }}; } + {% else %} + return 404 {% endif %} {% if WEBMAIL != 'none' %} From 425cdd5e7794061e09c9cd31d6cd275d6ca5ba24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20M=C3=B6hlmann?= Date: Fri, 7 Dec 2018 16:29:41 +0200 Subject: [PATCH 6/7] Fix syntax errors --- core/nginx/conf/nginx.conf | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/nginx/conf/nginx.conf b/core/nginx/conf/nginx.conf index a169cd75..b016b9ca 100644 --- a/core/nginx/conf/nginx.conf +++ b/core/nginx/conf/nginx.conf @@ -87,12 +87,13 @@ http { include /overrides/*.conf; # Actual logic - {% if WEBROOT_REDIRECT and WEB_WEBMAIL != '/' %} + location / { + {% if WEBROOT_REDIRECT and WEB_WEBMAIL != '/' %} return 301 {{ WEBROOT_REDIRECT }}; - } {% else %} - return 404 + return 404; + } {% endif %} {% if WEBMAIL != 'none' %} From 97d338e68aa3d3afdb9b845530e55de610b7cbb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20M=C3=B6hlmann?= Date: Fri, 7 Dec 2018 16:44:42 +0200 Subject: [PATCH 7/7] Rectify 'endif' placement --- core/nginx/conf/nginx.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/nginx/conf/nginx.conf b/core/nginx/conf/nginx.conf index b016b9ca..2fb4b8ef 100644 --- a/core/nginx/conf/nginx.conf +++ b/core/nginx/conf/nginx.conf @@ -93,8 +93,8 @@ http { return 301 {{ WEBROOT_REDIRECT }}; {% else %} return 404; - } {% endif %} + } {% if WEBMAIL != 'none' %} location {{ WEB_WEBMAIL }} {