Skip to content

Commit c8f430a

Browse files
authored
Add Jinja2 checks to all config template parameters (#66)
Resolves #4
1 parent 0c5c5d7 commit c8f430a

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ ENHANCEMENTS:
1919
BUG FIXES:
2020

2121
* Address inconsistent types within Jinja templates.
22+
* Add Jinja2 checks to all config template parameters to ensure that they are only included when appropriately defined.
2223
* Fix edge case where `proxy_pass` is still required when using `grpc_pass`.
2324

2425
## 0.3.2 (January 11, 2021)

defaults/main/template.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ nginx_config_main_template:
9999
access_log_location:
100100
- name: main
101101
location: /var/log/nginx/access.log
102+
sendfile: true
102103
tcp_nopush: true
103104
tcp_nodelay: true
104105
keepalive_timeout: 65

templates/nginx.conf.j2

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ load_module {{ nginx_module }};
66
{% endfor %}
77
{% endif %}
88

9-
user {{ nginx_config_main_template.user }};
10-
worker_processes {{ nginx_config_main_template.worker_processes }};
11-
9+
{% if nginx_config_main_template.user is defined %}
10+
user {{ nginx_config_main_template.user }};
11+
{% endif %}
12+
{% if nginx_config_main_template.worker_processes is defined %}
13+
worker_processes {{ nginx_config_main_template.worker_processes }};
14+
{% endif %}
1215
{% if nginx_config_main_template.worker_rlimit_nofile is defined %}
1316
worker_rlimit_nofile {{ nginx_config_main_template.worker_rlimit_nofile }};
1417
{% endif %}
@@ -19,12 +22,17 @@ worker_rlimit_nofile {{ nginx_config_main_template.worker_rlimit_nofile }};
1922
{% endfor %}
2023
{% endif %}
2124

22-
error_log {{ nginx_config_main_template.error_log.location | default("/var/log/nginx/error.log") }} {{ nginx_config_main_template.error_log.level | default("warn") }};
23-
pid {{ nginx_config_main_template.pid | default("/var/run/nginx.pid") }};
24-
25+
{% if nginx_config_main_template.error_log is defined %}
26+
error_log {{ nginx_config_main_template.error_log.location }} {{ nginx_config_main_template.error_log.level }};
27+
{% endif %}
28+
{% if nginx_config_main_template.pid is defined %}
29+
pid {{ nginx_config_main_template.pid }};
30+
{% endif %}
2531

2632
events {
33+
{% if nginx_config_main_template.worker_connections is defined %}
2734
worker_connections {{ nginx_config_main_template.worker_connections }};
35+
{% endif %}
2836
{% if nginx_config_main_template.events_custom_options is defined and nginx_config_main_template.events_custom_options | length %}
2937
{% for inline_option in nginx_config_main_template.events_custom_options %}
3038
{{ inline_option }}
@@ -36,7 +44,6 @@ events {
3644
http {
3745
include /etc/nginx/mime.types;
3846
default_type application/octet-stream;
39-
4047
{% if nginx_config_main_template.http_settings.app_protect_global is defined %}
4148
{% from 'http/app_protect.j2' import app_protect_global with context %}
4249
{% filter indent(4) %}
@@ -67,7 +74,9 @@ http {
6774
{% endfor %}
6875
{% endif %}
6976
{% endif %}
70-
sendfile on;
77+
{% if nginx_config_main_template.http_settings.sendfile is defined and nginx_config_main_template.http_settings.sendfile %}
78+
sendfile on;
79+
{% endif %}
7180
{% if nginx_config_main_template.http_settings.tcp_nopush is defined and nginx_config_main_template.http_settings.tcp_nopush %}
7281
tcp_nopush on;
7382
{% endif %}
@@ -125,7 +134,7 @@ http {
125134
}
126135
{% endif %}
127136

128-
{% if nginx_config_main_template.stream_enable %}
137+
{% if nginx_config_main_template.stream_enable is defined and nginx_config_main_template.stream_enable %}
129138
stream {
130139
{% if nginx_config_main_template.stream_custom_options is defined and nginx_config_main_template.stream_custom_options | length %}
131140
{% for inline_option in nginx_config_main_template.stream_custom_options %}

0 commit comments

Comments
 (0)