Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
bc25de4
[nginx] Configure precompressed file serving, remove Django compressi…
SAMurai-16 Feb 14, 2026
ce9f346
[nginx] Configure precompressed file serving, remove Django compressi…
SAMurai-16 Feb 14, 2026
7469520
[nginx] Configure precompressed file serving, remove Django compressi…
SAMurai-16 Feb 14, 2026
fd319d0
[nginx] Configure precompressed file serving, remove Django compressi…
SAMurai-16 Feb 14, 2026
52a24d6
[nginx] Configure precompressed file serving, remove Django compressi…
SAMurai-16 Feb 24, 2026
1963470
[nginx] Configure precompressed file serving, remove Django compressi…
SAMurai-16 Feb 24, 2026
77e6ac4
[nginx] Configure precompressed file serving, remove Django compressi…
SAMurai-16 Feb 24, 2026
c41622e
Merge branch 'master' into issues/599-configure-nginx
nemesifier Mar 6, 2026
ab1ca2c
[feature] Configured nginx to serve precompressed files (gzip/brotli)…
SAMurai-16 Mar 7, 2026
6e3fe34
[feature] Configured nginx to serve precompressed files (gzip/brotli)…
SAMurai-16 Mar 7, 2026
f2c664e
[feature] Configured nginx to serve precompressed files (gzip/brotli)…
SAMurai-16 Mar 7, 2026
fc461fb
[feature] Configured nginx to serve precompressed files (gzip/brotli)…
SAMurai-16 Mar 7, 2026
1ea1b50
[feature] Configured nginx to serve precompressed files (gzip/brotli)…
SAMurai-16 Mar 7, 2026
051518e
Apply suggestion from @kilo-code-bot[bot]
SAMurai-16 Mar 7, 2026
b6ea5f0
Apply suggestion from @kilo-code-bot[bot]
SAMurai-16 Mar 7, 2026
232075c
[feature] Configured nginx to serve precompressed files (gzip/brotli)…
SAMurai-16 Mar 7, 2026
31855fd
[feature] Configured nginx to serve precompressed files (gzip/brotli)…
SAMurai-16 Mar 7, 2026
b66c598
[feature] Configured nginx to serve precompressed files (gzip/brotli)…
SAMurai-16 Mar 7, 2026
0b59532
[feature] Configured nginx to serve precompressed files (gzip/brotli)…
SAMurai-16 Mar 7, 2026
2605500
Merge branch 'master' into issues/599-configure-nginx
nemesifier May 22, 2026
56df562
Merge branch 'openwisp:master' into issues/599-configure-nginx
SAMurai-16 Jun 3, 2026
6bac31e
Remove GZIP_STATIC_COMPRESSION and BROTLI_STATIC_COMPRESSION settings…
SAMurai-16 Jun 3, 2026
ac28d3e
Remove GZIP_STATIC_COMPRESSION and BROTLI_STATIC_COMPRESSION settings…
SAMurai-16 Jun 3, 2026
210a9d1
[fix] Update configuration for static compression #599
SAMurai-16 Jun 3, 2026
8aeec79
Merge branch 'master' into issues/599-configure-nginx
nemesifier Jul 2, 2026
ca38617
Merge branch 'master' into issues/599-configure-nginx
nemesifier Jul 3, 2026
e4a1b2a
[chores] Moved nginx logic to nginx.yml and install brotli packages
nemesifier Jul 3, 2026
c547d75
[fix] Fixed placement of static modules conf
nemesifier Jul 3, 2026
6833e28
[tests] Simplified test logic
nemesifier Jul 3, 2026
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
3 changes: 3 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ openwisp2_nginx_ssl_config:
- "font/opentype"
openwisp2_nginx_access_log: "{{ openwisp2_path }}/log/nginx.access.log"
openwisp2_nginx_error_log: "{{ openwisp2_path }}/log/nginx.error.log error"

openwisp2_nginx_gzip_static: auto
openwisp2_nginx_brotli_static: auto
# internationalization
openwisp2_internationalization: false
openwisp2_users_auth_api: true
Expand Down
13 changes: 13 additions & 0 deletions docs/user/role-variables.rst
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,19 @@ take a look at `the default values of these variables
- "application/xml"
- "application/x-font-ttf"
- "font/opentype"
# Precompressed gzip files serving control
# - 'auto' (default): automatically enabled when nginx gzip_static module is detected
# - true: require nginx gzip_static module and fail if it is unavailable
# - false: explicitly disable even when module is available
openwisp2_nginx_gzip_static: auto
# Precompressed brotli files serving control
# - 'auto' (default): automatically enabled when nginx ngx_brotli module is detected
# - true: require nginx ngx_brotli module and fail if it is unavailable
# - false: explicitly disable even when module is available
# Note: brotli is not shipped with stock nginx. The role installs
# libnginx-mod-http-brotli-static when available. Debian 11 and
# Ubuntu 22.04 do not provide this package.
openwisp2_nginx_brotli_static: auto
Comment thread
SAMurai-16 marked this conversation as resolved.
# nginx error log configuration
openwisp2_nginx_access_log: "{{ openwisp2_path }}/log/nginx.access.log"
openwisp2_nginx_error_log: "{{ openwisp2_path }}/log/nginx.error.log error"
Expand Down
3 changes: 3 additions & 0 deletions molecule/resources/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
openwisp2_uwsgi_extra_conf: |
single-interpreter=True
openwisp2_usage_metric_collection: false
# Test nginx static compression modules
openwisp2_nginx_gzip_static: auto
openwisp2_nginx_brotli_static: auto
openwisp2_extra_django_settings:
ACCOUNT_RATE_LIMITS: false
freeradius_eap_orgs:
Expand All @@ -24,18 +27,18 @@

pre_tasks:
- name: Update apt cache
apt:

Check failure on line 30 in molecule/resources/converge.yml

View workflow job for this annotation

GitHub Actions / Build debian12

fqcn[action-core]

Use FQCN for builtin module actions (apt).

Check failure on line 30 in molecule/resources/converge.yml

View workflow job for this annotation

GitHub Actions / Build debian13

fqcn[action-core]

Use FQCN for builtin module actions (apt).

Check failure on line 30 in molecule/resources/converge.yml

View workflow job for this annotation

GitHub Actions / Build ubuntu2604

fqcn[action-core]

Use FQCN for builtin module actions (apt).

Check failure on line 30 in molecule/resources/converge.yml

View workflow job for this annotation

GitHub Actions / Build ubuntu2404

fqcn[action-core]

Use FQCN for builtin module actions (apt).

Check failure on line 30 in molecule/resources/converge.yml

View workflow job for this annotation

GitHub Actions / Build ubuntu2204

fqcn[action-core]

Use FQCN for builtin module actions (apt).
update_cache: true
cache_valid_time: 600
when: ansible_os_family == 'Debian'

- name: Install net-tools
apt:

Check failure on line 36 in molecule/resources/converge.yml

View workflow job for this annotation

GitHub Actions / Build debian12

fqcn[action-core]

Use FQCN for builtin module actions (apt).

Check failure on line 36 in molecule/resources/converge.yml

View workflow job for this annotation

GitHub Actions / Build debian13

fqcn[action-core]

Use FQCN for builtin module actions (apt).

Check failure on line 36 in molecule/resources/converge.yml

View workflow job for this annotation

GitHub Actions / Build ubuntu2604

fqcn[action-core]

Use FQCN for builtin module actions (apt).

Check failure on line 36 in molecule/resources/converge.yml

View workflow job for this annotation

GitHub Actions / Build ubuntu2404

fqcn[action-core]

Use FQCN for builtin module actions (apt).

Check failure on line 36 in molecule/resources/converge.yml

View workflow job for this annotation

GitHub Actions / Build ubuntu2204

fqcn[action-core]

Use FQCN for builtin module actions (apt).
name:
- net-tools

- name: Remove the .dockerenv file
file:

Check failure on line 41 in molecule/resources/converge.yml

View workflow job for this annotation

GitHub Actions / Build debian12

fqcn[action-core]

Use FQCN for builtin module actions (file).

Check failure on line 41 in molecule/resources/converge.yml

View workflow job for this annotation

GitHub Actions / Build debian13

fqcn[action-core]

Use FQCN for builtin module actions (file).

Check failure on line 41 in molecule/resources/converge.yml

View workflow job for this annotation

GitHub Actions / Build ubuntu2604

fqcn[action-core]

Use FQCN for builtin module actions (file).

Check failure on line 41 in molecule/resources/converge.yml

View workflow job for this annotation

GitHub Actions / Build ubuntu2404

fqcn[action-core]

Use FQCN for builtin module actions (file).

Check failure on line 41 in molecule/resources/converge.yml

View workflow job for this annotation

GitHub Actions / Build ubuntu2204

fqcn[action-core]

Use FQCN for builtin module actions (file).
path: /.dockerenv
state: absent

Expand Down
70 changes: 70 additions & 0 deletions molecule/resources/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

tasks:
- name: Run a specific subset of tests
command: >

Check failure on line 10 in molecule/resources/verify.yml

View workflow job for this annotation

GitHub Actions / Build debian12

fqcn[action-core]

Use FQCN for builtin module actions (command).

Check failure on line 10 in molecule/resources/verify.yml

View workflow job for this annotation

GitHub Actions / Build debian13

fqcn[action-core]

Use FQCN for builtin module actions (command).

Check failure on line 10 in molecule/resources/verify.yml

View workflow job for this annotation

GitHub Actions / Build ubuntu2604

fqcn[action-core]

Use FQCN for builtin module actions (command).

Check failure on line 10 in molecule/resources/verify.yml

View workflow job for this annotation

GitHub Actions / Build ubuntu2404

fqcn[action-core]

Use FQCN for builtin module actions (command).

Check failure on line 10 in molecule/resources/verify.yml

View workflow job for this annotation

GitHub Actions / Build ubuntu2204

fqcn[action-core]

Use FQCN for builtin module actions (command).
/opt/openwisp2/env/bin/python /opt/openwisp2/manage.py test --keepdb --exclude skip_prod \
openwisp_controller.pki.tests.test_admin \
openwisp_controller.pki.tests.test_models \
Expand Down Expand Up @@ -38,22 +38,22 @@
changed_when: false

- name: Check if redis-server is running
command: systemctl status redis-server

Check failure on line 41 in molecule/resources/verify.yml

View workflow job for this annotation

GitHub Actions / Build debian12

fqcn[action-core]

Use FQCN for builtin module actions (command).

Check failure on line 41 in molecule/resources/verify.yml

View workflow job for this annotation

GitHub Actions / Build debian13

fqcn[action-core]

Use FQCN for builtin module actions (command).

Check failure on line 41 in molecule/resources/verify.yml

View workflow job for this annotation

GitHub Actions / Build ubuntu2604

fqcn[action-core]

Use FQCN for builtin module actions (command).

Check failure on line 41 in molecule/resources/verify.yml

View workflow job for this annotation

GitHub Actions / Build ubuntu2404

fqcn[action-core]

Use FQCN for builtin module actions (command).

Check failure on line 41 in molecule/resources/verify.yml

View workflow job for this annotation

GitHub Actions / Build ubuntu2204

fqcn[action-core]

Use FQCN for builtin module actions (command).
changed_when: false

- name: Chcke if redis is running
command: systemctl status redis

Check failure on line 45 in molecule/resources/verify.yml

View workflow job for this annotation

GitHub Actions / Build debian12

fqcn[action-core]

Use FQCN for builtin module actions (command).

Check failure on line 45 in molecule/resources/verify.yml

View workflow job for this annotation

GitHub Actions / Build debian13

fqcn[action-core]

Use FQCN for builtin module actions (command).

Check failure on line 45 in molecule/resources/verify.yml

View workflow job for this annotation

GitHub Actions / Build ubuntu2604

fqcn[action-core]

Use FQCN for builtin module actions (command).

Check failure on line 45 in molecule/resources/verify.yml

View workflow job for this annotation

GitHub Actions / Build ubuntu2404

fqcn[action-core]

Use FQCN for builtin module actions (command).

Check failure on line 45 in molecule/resources/verify.yml

View workflow job for this annotation

GitHub Actions / Build ubuntu2204

fqcn[action-core]

Use FQCN for builtin module actions (command).
changed_when: false

- name: Check Openwisp
block:
- name: Check if OpenWISP is running
uri:

Check failure on line 51 in molecule/resources/verify.yml

View workflow job for this annotation

GitHub Actions / Build debian12

fqcn[action-core]

Use FQCN for builtin module actions (uri).

Check failure on line 51 in molecule/resources/verify.yml

View workflow job for this annotation

GitHub Actions / Build debian13

fqcn[action-core]

Use FQCN for builtin module actions (uri).

Check failure on line 51 in molecule/resources/verify.yml

View workflow job for this annotation

GitHub Actions / Build ubuntu2604

fqcn[action-core]

Use FQCN for builtin module actions (uri).

Check failure on line 51 in molecule/resources/verify.yml

View workflow job for this annotation

GitHub Actions / Build ubuntu2404

fqcn[action-core]

Use FQCN for builtin module actions (uri).

Check failure on line 51 in molecule/resources/verify.yml

View workflow job for this annotation

GitHub Actions / Build ubuntu2204

fqcn[action-core]

Use FQCN for builtin module actions (uri).
url: "https://{{ inventory_hostname }}/admin/login/?next=/admin/"
validate_certs: false
rescue:
- name: Get OpenWisp log

Check failure on line 55 in molecule/resources/verify.yml

View workflow job for this annotation

GitHub Actions / Build debian12

no-changed-when

Commands should not change things if nothing needs doing.

Check failure on line 55 in molecule/resources/verify.yml

View workflow job for this annotation

GitHub Actions / Build debian13

no-changed-when

Commands should not change things if nothing needs doing.

Check failure on line 55 in molecule/resources/verify.yml

View workflow job for this annotation

GitHub Actions / Build ubuntu2604

no-changed-when

Commands should not change things if nothing needs doing.

Check failure on line 55 in molecule/resources/verify.yml

View workflow job for this annotation

GitHub Actions / Build ubuntu2404

no-changed-when

Commands should not change things if nothing needs doing.

Check failure on line 55 in molecule/resources/verify.yml

View workflow job for this annotation

GitHub Actions / Build ubuntu2204

no-changed-when

Commands should not change things if nothing needs doing.
command: "tail -n 500 {{ openwisp2_path }}/log/*.log"

Check failure on line 56 in molecule/resources/verify.yml

View workflow job for this annotation

GitHub Actions / Build debian12

fqcn[action-core]

Use FQCN for builtin module actions (command).

Check failure on line 56 in molecule/resources/verify.yml

View workflow job for this annotation

GitHub Actions / Build debian13

fqcn[action-core]

Use FQCN for builtin module actions (command).

Check failure on line 56 in molecule/resources/verify.yml

View workflow job for this annotation

GitHub Actions / Build ubuntu2604

fqcn[action-core]

Use FQCN for builtin module actions (command).

Check failure on line 56 in molecule/resources/verify.yml

View workflow job for this annotation

GitHub Actions / Build ubuntu2404

fqcn[action-core]

Use FQCN for builtin module actions (command).

Check failure on line 56 in molecule/resources/verify.yml

View workflow job for this annotation

GitHub Actions / Build ubuntu2204

fqcn[action-core]

Use FQCN for builtin module actions (command).
register: openwisp_log

- name: Show OpenWisp log
Expand All @@ -65,3 +65,73 @@
register: freeradius_eap_ports # Register the output and return code
failed_when: freeradius_eap_ports.rc | int != 0
changed_when: false

- name: Test nginx compression configuration
block:
- name: Get nginx build configuration
ansible.builtin.command: nginx -V
register: nginx_build_config
changed_when: false

- name: Get nginx loaded configuration
ansible.builtin.command: nginx -T
register: nginx_loaded_config
changed_when: false

- name: Set nginx static compression module availability facts
ansible.builtin.set_fact:
nginx_gzip_static_module_available: >-
{{ 'http_gzip_static_module' in (nginx_build_config.stderr | default('')) }}
nginx_brotli_static_module_available: >-
{{ 'brotli_static_module' in (
(nginx_build_config.stderr | default('')) ~
(nginx_loaded_config.stdout | default('')) ~
(nginx_loaded_config.stderr | default(''))
) }}

- name: Read nginx site configuration
ansible.builtin.slurp:
src: "/etc/nginx/sites-enabled/{{ inventory_hostname }}"
register: nginx_site_config

- name: Assert nginx static compression directives match module availability
ansible.builtin.assert:
that:
- >-
('gzip_static on;' in (nginx_site_config.content | b64decode)) ==
nginx_gzip_static_module_available
- >-
('brotli_static on;' in (nginx_site_config.content | b64decode)) ==
nginx_brotli_static_module_available
fail_msg: "Nginx static compression directives do not match available modules."

- name: Test nginx configuration syntax
ansible.builtin.command: nginx -t
changed_when: false

- name: Load role defaults for nginx static compression disabled test
ansible.builtin.include_vars:
file: "{{ playbook_dir }}/../../defaults/main.yml"

- name: Set nginx static compression facts with variables disabled
ansible.builtin.set_fact:
nginx_gzip_static_available: false
nginx_brotli_static_available: false

- name: Render nginx site configuration with static compression disabled
ansible.builtin.template:
src: "{{ playbook_dir }}/../../templates/nginx/site-conf.j2"
dest: /tmp/openwisp2-nginx-static-compression-disabled.conf
mode: "0644"

- name: Read nginx site configuration with static compression disabled
ansible.builtin.slurp:
src: /tmp/openwisp2-nginx-static-compression-disabled.conf
register: nginx_disabled_site_config

- name: Assert nginx static compression directives are disabled
ansible.builtin.assert:
that:
- "'gzip_static on;' not in (nginx_disabled_site_config.content | b64decode)"
- "'brotli_static on;' not in (nginx_disabled_site_config.content | b64decode)"
fail_msg: "Nginx static compression directives should be disabled."
10 changes: 10 additions & 0 deletions tasks/apt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@
name: nginx
when: openwisp2_nginx_install

- name: Install nginx brotli static module
ansible.builtin.apt:
name: libnginx-mod-http-brotli-static
when:
- openwisp2_nginx_install
- (openwisp2_nginx_brotli_static | string | lower) in ['true', 'auto']
# brotli static package not available on old distros
- not (ansible_distribution == 'Debian' and ansible_distribution_major_version == '11')
- not (ansible_distribution == 'Ubuntu' and ansible_distribution_version == '22.04')

- name: Install redis
ansible.builtin.apt:
name: redis-server
Expand Down
43 changes: 43 additions & 0 deletions tasks/nginx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,49 @@
openwisp2_nginx_client_max_body_size: "{{ openwisp2_firmware_upgrader_max_file_size }}"
when: openwisp2_firmware_upgrader

- name: Configure nginx static compression
block:
- name: Get nginx build configuration
ansible.builtin.command: nginx -V
register: nginx_build_config
changed_when: false

- name: Get nginx loaded configuration
ansible.builtin.command: nginx -T
register: nginx_loaded_config
changed_when: false

- name: Set nginx static compression facts
ansible.builtin.set_fact:
nginx_gzip_static_module_available: >-
{{ 'http_gzip_static_module' in (nginx_build_config.stderr | default('')) }}
nginx_brotli_static_module_available: >-
{{ 'brotli_static_module' in (
(nginx_build_config.stderr | default('')) ~
(nginx_loaded_config.stdout | default('')) ~
(nginx_loaded_config.stderr | default(''))
) }}

- name: Validate nginx static compression settings
ansible.builtin.assert:
that:
- >-
(openwisp2_nginx_gzip_static | string | lower) != 'true' or
nginx_gzip_static_module_available
- >-
(openwisp2_nginx_brotli_static | string | lower) != 'true' or
nginx_brotli_static_module_available
fail_msg: "A required nginx static compression module is not available."

- name: Set enabled nginx static compression facts
ansible.builtin.set_fact:
nginx_gzip_static_available: >-
{{ nginx_gzip_static_module_available and
(openwisp2_nginx_gzip_static | string | lower) in ['true', 'auto'] }}
nginx_brotli_static_available: >-
{{ nginx_brotli_static_module_available and
(openwisp2_nginx_brotli_static | string | lower) in ['true', 'auto'] }}

- name: Create public_html directory
ansible.builtin.file:
path: "{{ openwisp2_path }}/public_html"
Expand Down
6 changes: 6 additions & 0 deletions templates/nginx/site-conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ server {

location /static/ {
alias {{ openwisp2_path }}/static/;
{% if nginx_gzip_static_available | default(false) %}
gzip_static on;
{% endif %}
{% if nginx_brotli_static_available | default(false) %}
brotli_static on;
{% endif %}
}

location /media/ {
Expand Down
3 changes: 0 additions & 3 deletions templates/openwisp2/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,9 +531,6 @@
"BACKEND": "openwisp_utils.storage.CompressStaticFilesStorage",
},
}
# GZIP compression is handled by nginx
BROTLI_STATIC_COMPRESSION = False
GZIP_STATIC_COMPRESSION = False

{% if openwisp2_sentry.get("dsn") %}
RAVEN_CONFIG = {{ openwisp2_sentry | to_nice_json }}
Expand Down
Loading