Skip to content

Commit 602a894

Browse files
authored
Add mirror and gunzip modules (#242)
1 parent 91f6edf commit 602a894

File tree

6 files changed

+91
-1
lines changed

6 files changed

+91
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ ENHANCEMENTS:
1010

1111
* Bump the Ansible `community.general` collection to `4.6.1` and `community.docker` collection to `2.3.0`.
1212
* Add labels to loops in `tasks/config/template-config.yml` to reduce amount of output data.
13-
* Implement the `map`, `realip` and `split_clients` modules into the `http` core template.
13+
* Implement `gunzip`, `map`, `mirror`, `realip` and `split_clients` modules into `http` templates.
1414
* Streamline configuring SELinux.
1515

1616
BUG FIXES:

defaults/main/template.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,11 @@ nginx_config_http_template:
538538
exact_size: true # Boolean
539539
format: html
540540
localtime: false # Boolean
541+
gunzip: # Configure GUNZIP
542+
enable: true # Boolean
543+
buffers:
544+
number: 32 # Required
545+
size: 4k # Required
541546
gzip: # Configure GZIP
542547
enable: true # Boolean
543548
buffers:
@@ -641,6 +646,9 @@ nginx_config_http_template:
641646
content: # Dictionary or list of dictionaries
642647
- value: default
643648
new_value: 0
649+
mirror: # Configure Mirror directives
650+
request_body: true # Boolean
651+
uri: false # Required -- String or a list of strings -- Can alternatively be set to 'false'
644652
realip: # Configure RealIP directives
645653
set_real_ip_from: 0.0.0.0
646654
real_ip_header: X-Real-IP

molecule/default/converge.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,11 @@
422422
exact_size: true
423423
format: html
424424
localtime: true
425+
gunzip:
426+
enable: true
427+
buffers:
428+
number: 32
429+
size: 4k
425430
gzip:
426431
enable: true
427432
buffers:
@@ -589,11 +594,17 @@
589594
limit_except:
590595
method: GET
591596
directive: "allow all"
597+
mirror:
598+
uri: /mirror
592599
proxy:
593600
pass: http://frontend_servers/
594601
- location: /backend
595602
proxy:
596603
pass: http://backend_servers/
604+
- location: /mirror
605+
internal: true
606+
proxy:
607+
pass: http://127.0.0.1/
597608
- template_file: http/default.conf.j2
598609
deployment_location: /etc/nginx/conf.d/frontend_default.conf
599610
config:

molecule/plus/converge.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,11 @@
184184
- field: Accept-Encoding
185185
value: '""'
186186
socket_keepalive: false
187+
gunzip:
188+
enable: true
189+
buffers:
190+
number: 32
191+
size: 4k
187192
gzip:
188193
enable: true
189194
buffers:
@@ -519,6 +524,8 @@
519524
last_modified: false
520525
once: true
521526
- location: /backend
527+
mirror:
528+
uri: /mirror
522529
proxy_pass: http://backend_servers/
523530
proxy:
524531
set_header:
@@ -530,6 +537,10 @@
530537
value: $proxy_add_x_forwarded_for
531538
- field: X-Forwarded-Proto
532539
value: $scheme
540+
- location: /mirror
541+
internal: true
542+
proxy:
543+
pass: http://127.0.0.1/
533544
- template_file: http/default.conf.j2
534545
deployment_location: /etc/nginx/conf.d/frontend_default.conf
535546
config:

templates/http/default.conf.j2

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@
5656
{% from 'http/modules.j2' import autoindex with context %}
5757
{{ autoindex(item['config']['autoindex']) }}
5858
{%- endif %}
59+
{% if item['config']['gunzip'] is defined %}
60+
{% from 'http/modules.j2' import gunzip with context %}
61+
{{ gunzip(item['config']['gunzip']) }}
62+
{%- endif %}
5963
{% if item['config']['gzip'] is defined %}
6064
{% from 'http/modules.j2' import gzip with context %}
6165
{{ gzip(item['config']['gzip']) }}
@@ -84,6 +88,10 @@
8488
{% from 'http/modules.j2' import map with context %}
8589
{{ map(item['config']['map']) }}
8690
{%- endif %}
91+
{% if item['config']['mirror'] is defined %}
92+
{% from 'http/modules.j2' import mirror with context %}
93+
{{ mirror(item['config']['mirror']) }}
94+
{%- endif %}
8795
{% if item['config']['realip'] is defined %}
8896
{% from 'http/modules.j2' import realip with context %}
8997
{{ realip(item['config']['realip']) }}
@@ -186,6 +194,12 @@ server {
186194
{{ autoindex(server['autoindex']) }}
187195
{%- endfilter %}
188196
{% endif %}
197+
{% if server['gunzip'] is defined %}
198+
{% from 'http/modules.j2' import gunzip with context %}
199+
{% filter indent(4) %}
200+
{{ gunzip(server['gunzip']) }}
201+
{%- endfilter %}
202+
{% endif %}
189203
{% if server['gzip'] is defined %}
190204
{% from 'http/modules.j2' import gzip with context %}
191205
{% filter indent(4) %}
@@ -222,6 +236,12 @@ server {
222236
{{ log(server['log']) }}
223237
{%- endfilter %}
224238
{% endif %}
239+
{% if server['mirror'] is defined %}
240+
{% from 'http/modules.j2' import mirror with context %}
241+
{% filter indent(4) %}
242+
{{ mirror(server['mirror']) }}
243+
{%- endfilter %}
244+
{% endif %}
225245
{% if server['realip'] is defined %}
226246
{% from 'http/modules.j2' import realip with context %}
227247
{% filter indent(4) %}
@@ -322,6 +342,12 @@ server {
322342
{{ autoindex(location['autoindex']) }}
323343
{%- endfilter %}
324344
{% endif %}
345+
{% if location['gunzip'] is defined %}
346+
{% from 'http/modules.j2' import gunzip with context %}
347+
{% filter indent(8) %}
348+
{{ gunzip(location['gunzip']) }}
349+
{%- endfilter %}
350+
{% endif %}
325351
{% if location['gzip'] is defined %}
326352
{% from 'http/modules.j2' import gzip with context %}
327353
{% filter indent(8) %}
@@ -358,6 +384,12 @@ server {
358384
{{ log(location['log']) }}
359385
{%- endfilter %}
360386
{% endif %}
387+
{% if location['mirror'] is defined %}
388+
{% from 'http/modules.j2' import mirror with context %}
389+
{% filter indent(8) %}
390+
{{ mirror(location['mirror']) }}
391+
{%- endfilter %}
392+
{% endif %}
361393
{% if location['realip'] is defined %}
362394
{% from 'http/modules.j2' import realip with context %}
363395
{% filter indent(8) %}

templates/http/modules.j2

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ autoindex_localtime {{ autoindex['localtime'] | ternary('on', 'off') }};
3737

3838
{% endmacro %}
3939

40+
{# NGINX HTTP GUNZIP template -- ngx_http_gunzip_module #}
41+
{% macro gunzip(gunzip) %}
42+
{% if gunzip['enable'] is defined and gunzip['enable'] is boolean %}
43+
gunzip {{ gunzip['enable'] | ternary('on', 'off') }};
44+
{% endif %}
45+
{% if gunzip['buffers']['number'] is defined and gunzip['buffers']['size'] is defined %}
46+
gunzip_buffers {{ gunzip['buffers']['number'] }} {{ gunzip['buffers']['size'] }};
47+
{% endif %}
48+
49+
{% endmacro %}
50+
4051
{# NGINX HTTP GZIP template -- ngx_http_gzip_module #}
4152
{% macro gzip(gzip) %}
4253
{% if gzip['enable'] is defined and gzip['enable'] is boolean %}
@@ -225,6 +236,23 @@ map {{ map_data['string'] }} {{ map_data['variable'] }} {
225236

226237
{% endmacro %}
227238

239+
{# NGINX HTTP Mirror -- ngx_http_mirror_module #}
240+
{% macro mirror(mirror) %}
241+
{% if mirror is defined %}
242+
{% if mirror['uri'] is defined and mirror['uri'] is not mapping %}
243+
{% for uri in mirror['uri'] if mirror['uri'] is not string %}
244+
mirror {{ 'off' if not uri else uri }};
245+
{% else %}
246+
mirror {{ 'off' if not mirror['uri'] else mirror['uri'] }};
247+
{% endfor %}
248+
{% endif %}
249+
{% if mirror['request_body'] is defined and mirror['request_body'] is boolean %}
250+
mirror_request_body {{ mirror['request_body'] | ternary('on', 'off') }};
251+
{% endif %}
252+
{% endif %}
253+
254+
{% endmacro %}
255+
228256
{# NGINX HTTP RealIP -- ngx_http_realip_module #}
229257
{% macro realip(realip) %}
230258
{% if realip['set_real_ip_from'] is defined %}

0 commit comments

Comments
 (0)