From 92a61b8747378e3b0d5031d5f8f1204809e03b07 Mon Sep 17 00:00:00 2001 From: c-gabri Date: Sat, 27 Sep 2025 14:35:23 +0200 Subject: [PATCH 01/21] Allow custom Nginx external ports E.g. for installations running behind a reverse proxy --- docker-compose.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 854b8012..c1e221aa 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -131,8 +131,8 @@ services: - dashboard.internal - api.internal ports: - - "80:80" - - "443:443" + - "${NGINX_80_PORT:-80}:80" + - "${NGINX_SSL_PORT:-443}:443" depends_on: - dashboard - api From 3b681108315c6db919053331cc391f9282e287f0 Mon Sep 17 00:00:00 2001 From: c-gabri Date: Sat, 27 Sep 2025 15:39:28 +0200 Subject: [PATCH 02/21] Document custom Nginx external ports --- docs/user/settings.rst | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/user/settings.rst b/docs/user/settings.rst index 13bdd7fb..90ac34e3 100644 --- a/docs/user/settings.rst +++ b/docs/user/settings.rst @@ -869,6 +869,26 @@ Nginx - **Example:** ``index index.html index.htm;``. - **Default:** ``""`` (empty string). +``NGINX_SSL_PORT`` +~~~~~~~~~~~~~~~~~~~~ + +- **Explanation:** Nginx container external port. Useful to set if, for + example, OpenWISP is going to run behind a reverse proxy listening on + the default port on the same host. This variable is only applicable when + ``SSL_CERT_MODE`` is ``Yes`` or ``SelfSigned``. +- **Valid Values:** ``INTEGER``. +- **Default:** ``443``. + +``NGINX_80_PORT`` +~~~~~~~~~~~~~~~~~~~~ + +- **Explanation:** Nginx container external port. Useful to set if, for + example, OpenWISP is going to run behind a reverse proxy listening on + the default port on the same host. This variable is only applicable when + ``SSL_CERT_MODE`` is ``False``. +- **Valid Values:** ``INTEGER``. +- **Default:** ``80``. + ``NGINX_GZIP_SWITCH`` ~~~~~~~~~~~~~~~~~~~~~ From d5e7985b5c50a12a7c785bb0109576fe0a06e1e4 Mon Sep 17 00:00:00 2001 From: c-gabri Date: Sat, 27 Sep 2025 20:47:07 +0200 Subject: [PATCH 03/21] Change NGINX_80_PORT to NGINX_PORT --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index c1e221aa..38d75eaf 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -131,7 +131,7 @@ services: - dashboard.internal - api.internal ports: - - "${NGINX_80_PORT:-80}:80" + - "${NGINX_PORT:-80}:80" - "${NGINX_SSL_PORT:-443}:443" depends_on: - dashboard From b95cd48328d6f788cd3867b55e727c8691d51fa9 Mon Sep 17 00:00:00 2001 From: c-gabri Date: Sat, 27 Sep 2025 20:55:08 +0200 Subject: [PATCH 04/21] Correct documentation for NGINX_SSL_PORT and NGINX_PORT --- docs/user/settings.rst | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/docs/user/settings.rst b/docs/user/settings.rst index 90ac34e3..9357577b 100644 --- a/docs/user/settings.rst +++ b/docs/user/settings.rst @@ -872,20 +872,18 @@ Nginx ``NGINX_SSL_PORT`` ~~~~~~~~~~~~~~~~~~~~ -- **Explanation:** Nginx container external port. Useful to set if, for - example, OpenWISP is going to run behind a reverse proxy listening on - the default port on the same host. This variable is only applicable when - ``SSL_CERT_MODE`` is ``Yes`` or ``SelfSigned``. +- **Explanation:** Nginx container external HTTPS port. Useful to set if, + for example, OpenWISP is going to run behind a reverse proxy listening + on port 443 on the same host. - **Valid Values:** ``INTEGER``. - **Default:** ``443``. -``NGINX_80_PORT`` +``NGINX_PORT`` ~~~~~~~~~~~~~~~~~~~~ -- **Explanation:** Nginx container external port. Useful to set if, for - example, OpenWISP is going to run behind a reverse proxy listening on - the default port on the same host. This variable is only applicable when - ``SSL_CERT_MODE`` is ``False``. +- **Explanation:** Nginx container external HTTP port. Useful to set if, + for example, OpenWISP is going to run behind a reverse proxy listening + on port 80 on the same host. - **Valid Values:** ``INTEGER``. - **Default:** ``80``. From c5c2bac1a3210f439d58242798bb84da7f5ccae1 Mon Sep 17 00:00:00 2001 From: c-gabri Date: Sat, 27 Sep 2025 21:54:42 +0200 Subject: [PATCH 05/21] Format documentation with openwisp-qa-format --- docs/user/settings.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/user/settings.rst b/docs/user/settings.rst index 9357577b..b50e906d 100644 --- a/docs/user/settings.rst +++ b/docs/user/settings.rst @@ -870,7 +870,7 @@ Nginx - **Default:** ``""`` (empty string). ``NGINX_SSL_PORT`` -~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~ - **Explanation:** Nginx container external HTTPS port. Useful to set if, for example, OpenWISP is going to run behind a reverse proxy listening @@ -879,7 +879,7 @@ Nginx - **Default:** ``443``. ``NGINX_PORT`` -~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~ - **Explanation:** Nginx container external HTTP port. Useful to set if, for example, OpenWISP is going to run behind a reverse proxy listening From 3ad22cc2ba27234c173af8357cc34c31b05ba7ac Mon Sep 17 00:00:00 2001 From: c-gabri Date: Tue, 30 Sep 2025 20:38:55 +0200 Subject: [PATCH 06/21] Add default values for NGINX_PORT and NGINX_SSL_PORT --- .env | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.env b/.env index 573874aa..095c76cb 100644 --- a/.env +++ b/.env @@ -4,6 +4,9 @@ # Essential DASHBOARD_DOMAIN=dashboard.openwisp.org API_DOMAIN=api.openwisp.org +# NGINX +NGINX_PORT=80 +NGINX_SSL_PORT=443 # SSH Credentials Configurations SSH_PRIVATE_KEY_PATH=/home/openwisp/.ssh/id_ed25519 SSH_PUBLIC_KEY_PATH=/home/openwisp/.ssh/id_ed25519.pub From a5b84736a9c547fdb844536ddc560e8f75da88fd Mon Sep 17 00:00:00 2001 From: c-gabri Date: Wed, 1 Oct 2025 10:10:07 +0200 Subject: [PATCH 07/21] Add NGINX_PORT and NGINX_SSL_PORT build args to docker-compose.yml --- docker-compose.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index 38d75eaf..0a290219 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -117,6 +117,9 @@ services: build: context: images dockerfile: openwisp_nginx/Dockerfile + args: + NGINX_PORT: ${NGINX_PORT:-80} + NGINX_SSL_PORT: ${NGINX_SSL_PORT:-443} env_file: - .env volumes: From 62d6dc64a9e59c48c3fd170acb7448236c59e175 Mon Sep 17 00:00:00 2001 From: c-gabri Date: Wed, 1 Oct 2025 10:14:05 +0200 Subject: [PATCH 08/21] Add NGINX_SSL_PORT build arg to nginx Dockerfile --- images/openwisp_nginx/Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/images/openwisp_nginx/Dockerfile b/images/openwisp_nginx/Dockerfile index 3475bc20..732b1c08 100644 --- a/images/openwisp_nginx/Dockerfile +++ b/images/openwisp_nginx/Dockerfile @@ -20,6 +20,8 @@ COPY ./common/services.py \ RUN pip install --break-system-packages --no-cache-dir -r requirements.txt +ARG NGINX_SSL_PORT=443 + ENV MODULE_NAME=nginx \ PYTHONUNBUFFERED=1 \ DOLLAR=$ \ @@ -43,6 +45,7 @@ ENV MODULE_NAME=nginx \ NGINX_GZIP_TYPES='text/plain image/svg+xml application/json application/javascript text/xml text/css application/xml application/x-font-ttf font/opentype' \ NGINX_CUSTOM_FILE=False \ NINGX_REAL_REMOTE_ADDR='$real_ip' \ + NGINX_SSL_PORT=$NGINX_SSL_PORT \ # USWGI pass_port DASHBOARD_APP_PORT=8000 \ API_APP_PORT=8001 \ From c77682c90b998b048370e827835a44c7a512c5df Mon Sep 17 00:00:00 2001 From: c-gabri Date: Wed, 1 Oct 2025 10:19:23 +0200 Subject: [PATCH 09/21] Remove unnecessary NGINX_PORT build arg from docker-compose.yml --- docker-compose.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 0a290219..651a47d8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -118,7 +118,6 @@ services: context: images dockerfile: openwisp_nginx/Dockerfile args: - NGINX_PORT: ${NGINX_PORT:-80} NGINX_SSL_PORT: ${NGINX_SSL_PORT:-443} env_file: - .env From 3befcb93ec97756c38794834464c2e20067dd694 Mon Sep 17 00:00:00 2001 From: c-gabri Date: Wed, 1 Oct 2025 10:24:42 +0200 Subject: [PATCH 10/21] Add NGINX_SSL_PORT to HTTP->HTTPS redirect --- images/openwisp_nginx/openwisp.ssl.80.template.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/images/openwisp_nginx/openwisp.ssl.80.template.conf b/images/openwisp_nginx/openwisp.ssl.80.template.conf index 5cf05519..13790e96 100644 --- a/images/openwisp_nginx/openwisp.ssl.80.template.conf +++ b/images/openwisp_nginx/openwisp.ssl.80.template.conf @@ -9,5 +9,5 @@ server { location /.well-known/ { try_files ${DOLLAR}uri /dev/null =404; } - return 301 https://${DOLLAR}host${DOLLAR}request_uri; + return 301 https://${DOLLAR}host:${NGINX_SSL_PORT}${DOLLAR}request_uri; } From 0936668d25bfa8b78635475542041acd0e2ea7c5 Mon Sep 17 00:00:00 2001 From: c-gabri Date: Wed, 1 Oct 2025 10:29:15 +0200 Subject: [PATCH 11/21] Add NGINX_SSL_PORT to Content-Security-Policy header --- images/openwisp_nginx/openwisp.ssl.template.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/images/openwisp_nginx/openwisp.ssl.template.conf b/images/openwisp_nginx/openwisp.ssl.template.conf index 441c8b96..502a2ad4 100644 --- a/images/openwisp_nginx/openwisp.ssl.template.conf +++ b/images/openwisp_nginx/openwisp.ssl.template.conf @@ -24,7 +24,7 @@ server { add_header Referrer-Policy "same-site" always; add_header Permissions-Policy "interest-cohort=()" always; add_header Strict-Transport-Security "max-age=31536000" always; - add_header Content-Security-Policy "default-src http: https: data: blob: 'unsafe-inline'; script-src 'unsafe-eval' https: 'unsafe-inline' 'self'; frame-ancestors 'self'; connect-src *.${ROOT_DOMAIN} wss: 'self'; worker-src https://${DOMAIN} blob: 'self';" always; + add_header Content-Security-Policy "default-src http: https: data: blob: 'unsafe-inline'; script-src 'unsafe-eval' https: 'unsafe-inline' 'self'; frame-ancestors 'self'; connect-src *.${ROOT_DOMAIN}:${NGINX_SSL_PORT} wss: 'self'; worker-src https://${DOMAIN} blob: 'self';" always; # GZIP Configurations gzip ${NGINX_GZIP_SWITCH}; From 1738344aaefd75a579549032fd17544851b948f6 Mon Sep 17 00:00:00 2001 From: c-gabri Date: Wed, 1 Oct 2025 10:34:53 +0200 Subject: [PATCH 12/21] Add custom Nginx ports to CORS_ALLOWED_ORIGINS --- images/common/openwisp/settings.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/images/common/openwisp/settings.py b/images/common/openwisp/settings.py index cb3cd21b..10d977dd 100644 --- a/images/common/openwisp/settings.py +++ b/images/common/openwisp/settings.py @@ -50,11 +50,12 @@ ACCOUNT_LOGOUT_REDIRECT_URL = LOGIN_REDIRECT_URL ROOT_URLCONF = "openwisp.urls" HTTP_SCHEME = request_scheme() +HTTP_PORT = os.environ["NGINX_SSL_PORT"] if HTTP_SCHEME == 'https' else os.environ["NGINX_PORT"] # CORS CORS_ALLOWED_ORIGINS = [ - f'{HTTP_SCHEME}://{os.environ["DASHBOARD_DOMAIN"]}', - f'{HTTP_SCHEME}://{os.environ["API_DOMAIN"]}', + f'{HTTP_SCHEME}://{os.environ["DASHBOARD_DOMAIN"]}:{HTTP_PORT}', + f'{HTTP_SCHEME}://{os.environ["API_DOMAIN"]}:{HTTP_PORT}', ] + os.environ["DJANGO_CORS_HOSTS"].split(",") CORS_ALLOW_CREDENTIALS = True From 9ab464e8f2d5dab00105bf5deaf3e187b51dd2a0 Mon Sep 17 00:00:00 2001 From: c-gabri Date: Wed, 1 Oct 2025 10:39:57 +0200 Subject: [PATCH 13/21] Add custom Nginx ports to API_BASEURL --- images/openwisp_dashboard/module_settings.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/images/openwisp_dashboard/module_settings.py b/images/openwisp_dashboard/module_settings.py index 1cc66797..5fd19cfb 100644 --- a/images/openwisp_dashboard/module_settings.py +++ b/images/openwisp_dashboard/module_settings.py @@ -89,7 +89,9 @@ # pregenerate static gzip files to save CPU GZIP_STATIC_COMPRESSION = True -API_BASEURL = f'{request_scheme()}://{os.environ["API_DOMAIN"]}' +HTTP_SCHEME = request_scheme() +HTTP_PORT = os.environ["NGINX_SSL_PORT"] if HTTP_SCHEME == 'https' else os.environ["NGINX_PORT"] +API_BASEURL = f'{HTTP_SCHEME}://{os.environ["API_DOMAIN"]}:{HTTP_PORT}' OPENWISP_NETWORK_TOPOLOGY_API_URLCONF = "openwisp_network_topology.urls" OPENWISP_MONITORING_API_URLCONF = "openwisp_monitoring.urls" From 7d246f6f1e8c1502b0e2e349e0b4a02654967433 Mon Sep 17 00:00:00 2001 From: c-gabri Date: Wed, 1 Oct 2025 12:43:47 +0200 Subject: [PATCH 14/21] Make CORS_ALLOWED_ORIGINS work also with default Nginx ports --- images/common/openwisp/settings.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/images/common/openwisp/settings.py b/images/common/openwisp/settings.py index 10d977dd..8516e97e 100644 --- a/images/common/openwisp/settings.py +++ b/images/common/openwisp/settings.py @@ -51,11 +51,12 @@ ROOT_URLCONF = "openwisp.urls" HTTP_SCHEME = request_scheme() HTTP_PORT = os.environ["NGINX_SSL_PORT"] if HTTP_SCHEME == 'https' else os.environ["NGINX_PORT"] +HTTP_PORT = "" if HTTP_PORT in ["80", "443"] else f":{HTTP_PORT}" # CORS CORS_ALLOWED_ORIGINS = [ - f'{HTTP_SCHEME}://{os.environ["DASHBOARD_DOMAIN"]}:{HTTP_PORT}', - f'{HTTP_SCHEME}://{os.environ["API_DOMAIN"]}:{HTTP_PORT}', + f'{HTTP_SCHEME}://{os.environ["DASHBOARD_DOMAIN"]}{HTTP_PORT}', + f'{HTTP_SCHEME}://{os.environ["API_DOMAIN"]}{HTTP_PORT}', ] + os.environ["DJANGO_CORS_HOSTS"].split(",") CORS_ALLOW_CREDENTIALS = True From 02ff8090d74c30cb7c484d56f1e4654df844b778 Mon Sep 17 00:00:00 2001 From: c-gabri Date: Wed, 1 Oct 2025 16:12:24 +0200 Subject: [PATCH 15/21] Make custom Nginx ports work with SSL_CERT_MODE=External --- images/common/openwisp/settings.py | 10 ++++++++-- images/openwisp_dashboard/module_settings.py | 5 +++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/images/common/openwisp/settings.py b/images/common/openwisp/settings.py index 8516e97e..61c8cedd 100644 --- a/images/common/openwisp/settings.py +++ b/images/common/openwisp/settings.py @@ -50,8 +50,14 @@ ACCOUNT_LOGOUT_REDIRECT_URL = LOGIN_REDIRECT_URL ROOT_URLCONF = "openwisp.urls" HTTP_SCHEME = request_scheme() -HTTP_PORT = os.environ["NGINX_SSL_PORT"] if HTTP_SCHEME == 'https' else os.environ["NGINX_PORT"] -HTTP_PORT = "" if HTTP_PORT in ["80", "443"] else f":{HTTP_PORT}" +HTTP_PORT = os.environ["NGINX_SSL_PORT"] if HTTP_SCHEME == "https" else os.environ["NGINX_PORT"] +if ( + HTTP_SCHEME == "http" and HTTP_PORT == "80" or + HTTP_SCHEME == "https" and (HTTP_PORT == "443" or os.environ["SSL_CERT_MODE"].lower() == "external") +): + HTTP_PORT = "" +else: + HTTP_PORT = f":{HTTP_PORT}" # CORS CORS_ALLOWED_ORIGINS = [ diff --git a/images/openwisp_dashboard/module_settings.py b/images/openwisp_dashboard/module_settings.py index 5fd19cfb..1c1ab893 100644 --- a/images/openwisp_dashboard/module_settings.py +++ b/images/openwisp_dashboard/module_settings.py @@ -90,8 +90,9 @@ GZIP_STATIC_COMPRESSION = True HTTP_SCHEME = request_scheme() -HTTP_PORT = os.environ["NGINX_SSL_PORT"] if HTTP_SCHEME == 'https' else os.environ["NGINX_PORT"] -API_BASEURL = f'{HTTP_SCHEME}://{os.environ["API_DOMAIN"]}:{HTTP_PORT}' +HTTP_PORT = os.environ["NGINX_SSL_PORT"] if HTTP_SCHEME == "https" else os.environ["NGINX_PORT"] +HTTP_PORT = "" if HTTP_SCHEME == "https" and os.environ["SSL_CERT_MODE"].lower() == "external" else f":{HTTP_PORT}" +API_BASEURL = f'{HTTP_SCHEME}://{os.environ["API_DOMAIN"]}{HTTP_PORT}' OPENWISP_NETWORK_TOPOLOGY_API_URLCONF = "openwisp_network_topology.urls" OPENWISP_MONITORING_API_URLCONF = "openwisp_monitoring.urls" From 06cd12fc13418ac9b6d1d76493f16ea644db7157 Mon Sep 17 00:00:00 2001 From: c-gabri Date: Wed, 1 Oct 2025 16:29:18 +0200 Subject: [PATCH 16/21] Improve documentation for non-default Nginx ports --- docs/user/settings.rst | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/docs/user/settings.rst b/docs/user/settings.rst index b50e906d..13201af2 100644 --- a/docs/user/settings.rst +++ b/docs/user/settings.rst @@ -83,13 +83,13 @@ properly on your system. ``SSL_CERT_MODE`` ~~~~~~~~~~~~~~~~~ -- **Explanation:** Flag to enable or disable HTTPs. If it is set to +- **Explanation:** Flag to enable or disable HTTPS. If it is set to ``Yes``, letsencrypt certificates are automatically fetched with the help of certbot and a cronjob to ensure they stay updated is added. If - it is set to ``SelfSigned``, self-signed certificates are used and - cronjob for the certificates is set. If set to ``No``, site is - accessible via HTTP, if set if ``EXTERNAL``, it tells HTTPs is used but - managed by external tool like loadbalancer / provider. Setting this + it is set to ``SelfSigned``, self-signed certificates are used and a + cronjob for the certificates is set. If set to ``No``, the site is + accessible via HTTP. If set to ``External``, it tells HTTPS is used but + managed by an external tool like a loadbalancer/provider. Setting this option as ``No`` is not recommended and might break some features, only do it when you know what you are doing. - **Valid Values:** ``External``, ``Yes``, ``SelfSigned``, ``No``. @@ -872,18 +872,20 @@ Nginx ``NGINX_SSL_PORT`` ~~~~~~~~~~~~~~~~~~ -- **Explanation:** Nginx container external HTTPS port. Useful to set if, - for example, OpenWISP is going to run behind a reverse proxy listening - on port 443 on the same host. +- **Explanation:** Nginx container external HTTPS port. Change if, for + example, OpenWISP runs behind a reverse proxy listening on port 443 on + the same host. Non-default ports are incompatible with + ``SSL_CERT_MODE=Yes``. - **Valid Values:** ``INTEGER``. - **Default:** ``443``. ``NGINX_PORT`` ~~~~~~~~~~~~~~ -- **Explanation:** Nginx container external HTTP port. Useful to set if, - for example, OpenWISP is going to run behind a reverse proxy listening - on port 80 on the same host. +- **Explanation:** Nginx container external HTTP port. Change if, for + example, OpenWISP runs behind a reverse proxy listening on port 80 on + the same host. Non-default ports are incompatible with + ``SSL_CERT_MODE=Yes``. - **Valid Values:** ``INTEGER``. - **Default:** ``80``. From 48f944ac1ab9f4901e79dd005718ac5250ff2b28 Mon Sep 17 00:00:00 2001 From: c-gabri Date: Wed, 1 Oct 2025 16:42:45 +0200 Subject: [PATCH 17/21] Reformat settings.rst with openwisp-qa-format --- docs/user/settings.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/user/settings.rst b/docs/user/settings.rst index 13201af2..5bc46d9c 100644 --- a/docs/user/settings.rst +++ b/docs/user/settings.rst @@ -882,7 +882,7 @@ Nginx ``NGINX_PORT`` ~~~~~~~~~~~~~~ -- **Explanation:** Nginx container external HTTP port. Change if, for +- **Explanation:** Nginx container external HTTP port. Change if, for example, OpenWISP runs behind a reverse proxy listening on port 80 on the same host. Non-default ports are incompatible with ``SSL_CERT_MODE=Yes``. From d2fef47d2675ebed5c84c2e891b294b122a1bf0f Mon Sep 17 00:00:00 2001 From: c-gabri Date: Thu, 2 Oct 2025 16:34:02 +0200 Subject: [PATCH 18/21] Remove unnecessary build arg NGINX_SSL_PORT --- docker-compose.yml | 2 -- images/openwisp_nginx/Dockerfile | 4 +--- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 651a47d8..38d75eaf 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -117,8 +117,6 @@ services: build: context: images dockerfile: openwisp_nginx/Dockerfile - args: - NGINX_SSL_PORT: ${NGINX_SSL_PORT:-443} env_file: - .env volumes: diff --git a/images/openwisp_nginx/Dockerfile b/images/openwisp_nginx/Dockerfile index 732b1c08..bcd5b94e 100644 --- a/images/openwisp_nginx/Dockerfile +++ b/images/openwisp_nginx/Dockerfile @@ -20,8 +20,6 @@ COPY ./common/services.py \ RUN pip install --break-system-packages --no-cache-dir -r requirements.txt -ARG NGINX_SSL_PORT=443 - ENV MODULE_NAME=nginx \ PYTHONUNBUFFERED=1 \ DOLLAR=$ \ @@ -45,7 +43,7 @@ ENV MODULE_NAME=nginx \ NGINX_GZIP_TYPES='text/plain image/svg+xml application/json application/javascript text/xml text/css application/xml application/x-font-ttf font/opentype' \ NGINX_CUSTOM_FILE=False \ NINGX_REAL_REMOTE_ADDR='$real_ip' \ - NGINX_SSL_PORT=$NGINX_SSL_PORT \ + NGINX_SSL_PORT=443 \ # USWGI pass_port DASHBOARD_APP_PORT=8000 \ API_APP_PORT=8001 \ From 671ce028ca53a04ba83630d14a1f236115fc37a3 Mon Sep 17 00:00:00 2001 From: c-gabri Date: Thu, 2 Oct 2025 16:38:01 +0200 Subject: [PATCH 19/21] Make it optional to set Nginx ports in .env --- .env | 3 --- images/common/openwisp/settings.py | 2 +- images/openwisp_dashboard/module_settings.py | 2 +- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/.env b/.env index 095c76cb..573874aa 100644 --- a/.env +++ b/.env @@ -4,9 +4,6 @@ # Essential DASHBOARD_DOMAIN=dashboard.openwisp.org API_DOMAIN=api.openwisp.org -# NGINX -NGINX_PORT=80 -NGINX_SSL_PORT=443 # SSH Credentials Configurations SSH_PRIVATE_KEY_PATH=/home/openwisp/.ssh/id_ed25519 SSH_PUBLIC_KEY_PATH=/home/openwisp/.ssh/id_ed25519.pub diff --git a/images/common/openwisp/settings.py b/images/common/openwisp/settings.py index 61c8cedd..c9c77317 100644 --- a/images/common/openwisp/settings.py +++ b/images/common/openwisp/settings.py @@ -50,7 +50,7 @@ ACCOUNT_LOGOUT_REDIRECT_URL = LOGIN_REDIRECT_URL ROOT_URLCONF = "openwisp.urls" HTTP_SCHEME = request_scheme() -HTTP_PORT = os.environ["NGINX_SSL_PORT"] if HTTP_SCHEME == "https" else os.environ["NGINX_PORT"] +HTTP_PORT = os.getenv("NGINX_SSL_PORT", "443") if HTTP_SCHEME == "https" else os.getenv("NGINX_PORT", "80") if ( HTTP_SCHEME == "http" and HTTP_PORT == "80" or HTTP_SCHEME == "https" and (HTTP_PORT == "443" or os.environ["SSL_CERT_MODE"].lower() == "external") diff --git a/images/openwisp_dashboard/module_settings.py b/images/openwisp_dashboard/module_settings.py index 1c1ab893..05fb7495 100644 --- a/images/openwisp_dashboard/module_settings.py +++ b/images/openwisp_dashboard/module_settings.py @@ -90,7 +90,7 @@ GZIP_STATIC_COMPRESSION = True HTTP_SCHEME = request_scheme() -HTTP_PORT = os.environ["NGINX_SSL_PORT"] if HTTP_SCHEME == "https" else os.environ["NGINX_PORT"] +HTTP_PORT = os.getenv("NGINX_SSL_PORT", "443") if HTTP_SCHEME == "https" else os.getenv("NGINX_PORT", "80") HTTP_PORT = "" if HTTP_SCHEME == "https" and os.environ["SSL_CERT_MODE"].lower() == "external" else f":{HTTP_PORT}" API_BASEURL = f'{HTTP_SCHEME}://{os.environ["API_DOMAIN"]}{HTTP_PORT}' From 93086af0d16bf8aaa807d24b97903a8acd57b32d Mon Sep 17 00:00:00 2001 From: c-gabri Date: Thu, 2 Oct 2025 19:59:06 +0200 Subject: [PATCH 20/21] [fix] Reformat with openwisp-qa-format #496 Fixes #496 --- images/common/openwisp/settings.py | 13 ++++++++++--- images/openwisp_dashboard/module_settings.py | 12 ++++++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/images/common/openwisp/settings.py b/images/common/openwisp/settings.py index c9c77317..39ab9605 100644 --- a/images/common/openwisp/settings.py +++ b/images/common/openwisp/settings.py @@ -5,6 +5,7 @@ from urllib.parse import quote import tldextract + from openwisp.utils import ( env_bool, is_string_env_bool, @@ -50,10 +51,16 @@ ACCOUNT_LOGOUT_REDIRECT_URL = LOGIN_REDIRECT_URL ROOT_URLCONF = "openwisp.urls" HTTP_SCHEME = request_scheme() -HTTP_PORT = os.getenv("NGINX_SSL_PORT", "443") if HTTP_SCHEME == "https" else os.getenv("NGINX_PORT", "80") +HTTP_PORT = ( + os.getenv("NGINX_SSL_PORT", "443") + if HTTP_SCHEME == "https" + else os.getenv("NGINX_PORT", "80") +) if ( - HTTP_SCHEME == "http" and HTTP_PORT == "80" or - HTTP_SCHEME == "https" and (HTTP_PORT == "443" or os.environ["SSL_CERT_MODE"].lower() == "external") + HTTP_SCHEME == "http" + and HTTP_PORT == "80" + or HTTP_SCHEME == "https" + and (HTTP_PORT == "443" or os.environ["SSL_CERT_MODE"].lower() == "external") ): HTTP_PORT = "" else: diff --git a/images/openwisp_dashboard/module_settings.py b/images/openwisp_dashboard/module_settings.py index 05fb7495..6c092abf 100644 --- a/images/openwisp_dashboard/module_settings.py +++ b/images/openwisp_dashboard/module_settings.py @@ -90,8 +90,16 @@ GZIP_STATIC_COMPRESSION = True HTTP_SCHEME = request_scheme() -HTTP_PORT = os.getenv("NGINX_SSL_PORT", "443") if HTTP_SCHEME == "https" else os.getenv("NGINX_PORT", "80") -HTTP_PORT = "" if HTTP_SCHEME == "https" and os.environ["SSL_CERT_MODE"].lower() == "external" else f":{HTTP_PORT}" +HTTP_PORT = ( + os.getenv("NGINX_SSL_PORT", "443") + if HTTP_SCHEME == "https" + else os.getenv("NGINX_PORT", "80") +) +HTTP_PORT = ( + "" + if HTTP_SCHEME == "https" and os.environ["SSL_CERT_MODE"].lower() == "external" + else f":{HTTP_PORT}" +) API_BASEURL = f'{HTTP_SCHEME}://{os.environ["API_DOMAIN"]}{HTTP_PORT}' OPENWISP_NETWORK_TOPOLOGY_API_URLCONF = "openwisp_network_topology.urls" From bea9b2553ccda8e62ec39befaefe12efa656d650 Mon Sep 17 00:00:00 2001 From: Federico Capoano Date: Thu, 9 Oct 2025 19:46:16 -0300 Subject: [PATCH 21/21] [chores] Fixed minor QA issue --- images/common/openwisp/settings.py | 1 - 1 file changed, 1 deletion(-) diff --git a/images/common/openwisp/settings.py b/images/common/openwisp/settings.py index 39ab9605..bdf16b78 100644 --- a/images/common/openwisp/settings.py +++ b/images/common/openwisp/settings.py @@ -5,7 +5,6 @@ from urllib.parse import quote import tldextract - from openwisp.utils import ( env_bool, is_string_env_bool,