Skip to content

Commit

Permalink
Add Jinja2 checks to all config template parameters
Browse files Browse the repository at this point in the history
Resolves #4
  • Loading branch information
alessfg committed Jan 28, 2021
1 parent 0c5c5d7 commit e9009c0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ ENHANCEMENTS:
BUG FIXES:

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

## 0.3.2 (January 11, 2021)
Expand Down
1 change: 1 addition & 0 deletions defaults/main/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ nginx_config_main_template:
access_log_location:
- name: main
location: /var/log/nginx/access.log
sendfile: true
tcp_nopush: true
tcp_nodelay: true
keepalive_timeout: 65
Expand Down
27 changes: 18 additions & 9 deletions templates/nginx.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ load_module {{ nginx_module }};
{% endfor %}
{% endif %}

user {{ nginx_config_main_template.user }};
worker_processes {{ nginx_config_main_template.worker_processes }};

{% if nginx_config_main_template.user is defined %}
user {{ nginx_config_main_template.user }};
{% endif %}
{% if nginx_config_main_template.worker_processes is defined %}
worker_processes {{ nginx_config_main_template.worker_processes }};
{% endif %}
{% if nginx_config_main_template.worker_rlimit_nofile is defined %}
worker_rlimit_nofile {{ nginx_config_main_template.worker_rlimit_nofile }};
{% endif %}
Expand All @@ -19,12 +22,17 @@ worker_rlimit_nofile {{ nginx_config_main_template.worker_rlimit_nofile }};
{% endfor %}
{% endif %}

error_log {{ nginx_config_main_template.error_log.location | default("/var/log/nginx/error.log") }} {{ nginx_config_main_template.error_log.level | default("warn") }};
pid {{ nginx_config_main_template.pid | default("/var/run/nginx.pid") }};

{% if nginx_config_main_template.error_log is defined %}
error_log {{ nginx_config_main_template.error_log.location }} {{ nginx_config_main_template.error_log.level }};
{% endif %}
{% if nginx_config_main_template.pid is defined %}
pid {{ nginx_config_main_template.pid }};
{% endif %}

events {
{% if nginx_config_main_template.worker_connections is defined %}
worker_connections {{ nginx_config_main_template.worker_connections }};
{% endif %}
{% if nginx_config_main_template.events_custom_options is defined and nginx_config_main_template.events_custom_options | length %}
{% for inline_option in nginx_config_main_template.events_custom_options %}
{{ inline_option }}
Expand All @@ -36,7 +44,6 @@ events {
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

{% if nginx_config_main_template.http_settings.app_protect_global is defined %}
{% from 'http/app_protect.j2' import app_protect_global with context %}
{% filter indent(4) %}
Expand Down Expand Up @@ -67,7 +74,9 @@ http {
{% endfor %}
{% endif %}
{% endif %}
sendfile on;
{% if nginx_config_main_template.http_settings.sendfile is defined and nginx_config_main_template.http_settings.sendfile %}
sendfile on;
{% endif %}
{% if nginx_config_main_template.http_settings.tcp_nopush is defined and nginx_config_main_template.http_settings.tcp_nopush %}
tcp_nopush on;
{% endif %}
Expand Down Expand Up @@ -125,7 +134,7 @@ http {
}
{% endif %}

{% if nginx_config_main_template.stream_enable %}
{% if nginx_config_main_template.stream_enable is defined and nginx_config_main_template.stream_enable %}
stream {
{% if nginx_config_main_template.stream_custom_options is defined and nginx_config_main_template.stream_custom_options | length %}
{% for inline_option in nginx_config_main_template.stream_custom_options %}
Expand Down

0 comments on commit e9009c0

Please sign in to comment.