Skip to content

Commit ab1ca2c

Browse files
committed
[feature] Configured nginx to serve precompressed files (gzip/brotli) #599
Remove GZIP_STATIC_COMPRESSION and BROTLI_STATIC_COMPRESSION settings from Django configuration as they are no longer valid with the new openwisp-utils package. Configure nginx to serve precompressed files by adding gzip_static and brotli_static directives to the SSL configuration. This improves performance by serving pre-compressed .gz and .br files directly when available, rather than compressing on-the-fly. Updated templates/openwisp2/settings.py to remove obsolete compression settings, modified defaults/main.yml to add precompressed file serving configuration, and updated documentation in docs/user/role-variables.rst. Fixes #599
1 parent c41622e commit ab1ca2c

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

defaults/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,12 @@ openwisp2_nginx_ssl_config:
161161
- "application/x-font-ttf"
162162
- "font/opentype"
163163
# Enable precompressed gzip files serving (requires nginx with gzip_static module)
164+
# Note: The role will attempt to install libnginx-mod-http-gzip-static when enabled
165+
# If the module is not available, nginx will fail with "unknown directive" error
164166
openwisp2_nginx_gzip_static: false
165167
# Enable precompressed brotli files serving (requires nginx with ngx_brotli module)
168+
# Note: The role will attempt to install libnginx-mod-brotli when enabled
169+
# If the module is not available, nginx will fail with "unknown directive" error
166170
openwisp2_nginx_brotli_static: false
167171
openwisp2_nginx_access_log: "{{ openwisp2_path }}/log/nginx.access.log"
168172
openwisp2_nginx_error_log: "{{ openwisp2_path }}/log/nginx.error.log error"

molecule/resources/converge.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
openwisp2_uwsgi_extra_conf: |
1313
single-interpreter=True
1414
openwisp2_usage_metric_collection: false
15+
openwisp2_influxdb_install: false # Disable InfluxDB for testing to avoid repository issues
16+
# Test nginx static compression modules
17+
openwisp2_nginx_gzip_static: true
18+
openwisp2_nginx_brotli_static: true
1519
openwisp2_extra_django_settings:
1620
ACCOUNT_RATE_LIMITS: false
1721
freeradius_eap_orgs:

molecule/resources/verify.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
command: systemctl status redis-server
4242
changed_when: false
4343

44-
- name: Chcke if redis is running
44+
- name: Check if redis is running
4545
command: systemctl status redis
4646
changed_when: false
4747

@@ -65,3 +65,15 @@
6565
register: freeradius_eap_ports # Register the output and return code
6666
failed_when: freeradius_eap_ports.rc | int != 0
6767
changed_when: false
68+
69+
- name: Test nginx compression configuration
70+
block:
71+
# Test that enabled features appear in nginx config
72+
- name: Check nginx config contains gzip_static and brotli_static directives
73+
shell: "grep 'gzip_static on;' /etc/nginx/sites-enabled/openwisp2 && grep 'brotli_static on;' /etc/nginx/sites-enabled/openwisp2"
74+
changed_when: false
75+
76+
# Test nginx configuration syntax is valid
77+
- name: Test nginx configuration syntax
78+
shell: "nginx -t"
79+
changed_when: false

tasks/apt.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@
4040
name: nginx
4141
when: openwisp2_nginx_install
4242

43+
- name: Install nginx gzip static module
44+
apt:
45+
name: libnginx-mod-http-gzip-static
46+
when: openwisp2_nginx_install and openwisp2_nginx_gzip_static
47+
ignore_errors: true # May not be available on all distributions
48+
49+
- name: Install nginx brotli module
50+
apt:
51+
name: libnginx-mod-brotli
52+
when: openwisp2_nginx_install and openwisp2_nginx_brotli_static
53+
ignore_errors: true # May not be available on all distributions
54+
4355
- name: Install redis
4456
apt:
4557
name: redis-server

0 commit comments

Comments
 (0)