Skip to content

Commit 335492e

Browse files
authored
Allow setting access_log to "off" (#11)
1 parent 18a9395 commit 335492e

File tree

5 files changed

+22
-0
lines changed

5 files changed

+22
-0
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## 0.x (Unreleased)
4+
5+
ENHANCEMENTS:
6+
7+
* Improve configuration templating capabilities:
8+
* Allow setting `access_log`/`access_log_location` to `off`.
9+
310
## 0.1.0 (August 19, 2020)
411

512
Initial release of the NGINX Config role. Contains all NGINX Config related features previously available on the [NGINX Ansible role](https://github.com/nginxinc/ansible-role-nginx).

defaults/main/template.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ nginx_config_http_template:
9494
include_files: []
9595
http_error_pages: {}
9696
error_page: /usr/share/nginx/html
97+
# access_log: "off" # Cancels all access_log directives on the current level
9798
access_log:
9899
- name: main
99100
location: /var/log/nginx/access.log

molecule/common/playbooks/default_converge.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@
7676
http_error_pages:
7777
404: /404.html
7878
error_page: /usr/share/nginx/html
79+
access_log:
80+
- name: main
81+
location: /var/log/nginx/access.log
7982
client_max_body_size: 512k
8083
proxy_hide_headers:
8184
- X-Powered-By
@@ -254,6 +257,7 @@
254257
opts: []
255258
server_name: localhost
256259
error_page: /usr/share/nginx/html
260+
access_log: "off"
257261
autoindex: false
258262
sub_filter:
259263
sub_filters:

templates/http/default.conf.j2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,10 +491,14 @@ server {
491491
{% endif %}
492492

493493
{% if item.value.servers[server].access_log is defined %}
494+
{% if item.value.servers[server].access_log is sameas false or item.value.servers[server].access_log == "off" %}
495+
access_log off;
496+
{% else %}
494497
{% for access_log in item.value.servers[server].access_log %}
495498
access_log {{ access_log.location }} {{ access_log.name }};
496499
{% endfor %}
497500
{% endif %}
501+
{% endif %}
498502
{% if item.value.servers[server].error_log is defined %}
499503
error_log {{ item.value.servers[server].error_log.location }} {{ item.value.servers[server].error_log.level }};
500504
{% endif %}

templates/nginx.conf.j2

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,15 @@ http {
6666
log_format {{ access_log.name }} {{ access_log.format }};
6767
{% endfor %}
6868

69+
{% if nginx_config_main_template.http_settings.access_log_location is defined %}
70+
{% if nginx_config_main_template.http_settings.access_log_location is sameas false or nginx_config_main_template.http_settings.access_log_location == "off" %}
71+
access_log off;
72+
{% else %}
6973
{% for access_log in nginx_config_main_template.http_settings.access_log_location %}
7074
access_log {{ access_log.location }} {{ access_log.name }};
7175
{% endfor %}
76+
{% endif %}
77+
{% endif %}
7278

7379
sendfile on;
7480

0 commit comments

Comments
 (0)