Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
92a61b8
Allow custom Nginx external ports
c-gabri Sep 27, 2025
3b68110
Document custom Nginx external ports
c-gabri Sep 27, 2025
d5e7985
Change NGINX_80_PORT to NGINX_PORT
c-gabri Sep 27, 2025
b95cd48
Correct documentation for NGINX_SSL_PORT and NGINX_PORT
c-gabri Sep 27, 2025
c5c2bac
Format documentation with openwisp-qa-format
c-gabri Sep 27, 2025
b519d25
Merge branch 'master' into master
nemesifier Sep 29, 2025
3ad22cc
Add default values for NGINX_PORT and NGINX_SSL_PORT
c-gabri Sep 30, 2025
a5b8473
Add NGINX_PORT and NGINX_SSL_PORT build args to docker-compose.yml
c-gabri Oct 1, 2025
62d6dc6
Add NGINX_SSL_PORT build arg to nginx Dockerfile
c-gabri Oct 1, 2025
c77682c
Remove unnecessary NGINX_PORT build arg from docker-compose.yml
c-gabri Oct 1, 2025
3befcb9
Add NGINX_SSL_PORT to HTTP->HTTPS redirect
c-gabri Oct 1, 2025
0936668
Add NGINX_SSL_PORT to Content-Security-Policy header
c-gabri Oct 1, 2025
1738344
Add custom Nginx ports to CORS_ALLOWED_ORIGINS
c-gabri Oct 1, 2025
9ab464e
Add custom Nginx ports to API_BASEURL
c-gabri Oct 1, 2025
7d246f6
Make CORS_ALLOWED_ORIGINS work also with default Nginx ports
c-gabri Oct 1, 2025
02ff809
Make custom Nginx ports work with SSL_CERT_MODE=External
c-gabri Oct 1, 2025
06cd12f
Improve documentation for non-default Nginx ports
c-gabri Oct 1, 2025
48f944a
Reformat settings.rst with openwisp-qa-format
c-gabri Oct 1, 2025
d2fef47
Remove unnecessary build arg NGINX_SSL_PORT
c-gabri Oct 2, 2025
671ce02
Make it optional to set Nginx ports in .env
c-gabri Oct 2, 2025
93086af
[fix] Reformat with openwisp-qa-format #496
c-gabri Oct 2, 2025
bdbd5ac
Merge remote-tracking branch 'upstream/master'
c-gabri Oct 5, 2025
0e1c1ec
Merge branch 'master' into master
nemesifier Oct 7, 2025
967d44f
Merge branch 'master' into master
nemesifier Oct 9, 2025
bea9b25
[chores] Fixed minor QA issue
nemesifier Oct 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ services:
- dashboard.internal
- api.internal
ports:
- "80:80"
- "443:443"
- "${NGINX_PORT:-80}:80"
- "${NGINX_SSL_PORT:-443}:443"
depends_on:
- dashboard
- api
Expand Down
30 changes: 25 additions & 5 deletions docs/user/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
Expand Down Expand Up @@ -869,6 +869,26 @@ Nginx
- **Example:** ``index index.html index.htm;``.
- **Default:** ``""`` (empty string).

``NGINX_SSL_PORT``
~~~~~~~~~~~~~~~~~~

- **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. 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``.

``NGINX_GZIP_SWITCH``
~~~~~~~~~~~~~~~~~~~~~

Expand Down
18 changes: 16 additions & 2 deletions images/common/openwisp/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,25 @@
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")
)
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 = [
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

Expand Down
13 changes: 12 additions & 1 deletion images/openwisp_dashboard/module_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,18 @@
# 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.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"
OPENWISP_MONITORING_API_URLCONF = "openwisp_monitoring.urls"
Expand Down
1 change: 1 addition & 0 deletions images/openwisp_nginx/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,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=443 \
# USWGI pass_port
DASHBOARD_APP_PORT=8000 \
API_APP_PORT=8001 \
Expand Down
2 changes: 1 addition & 1 deletion images/openwisp_nginx/openwisp.ssl.80.template.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion images/openwisp_nginx/openwisp.ssl.template.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down