diff --git a/README.md b/README.md index 2396d74..de77a51 100644 --- a/README.md +++ b/README.md @@ -336,10 +336,21 @@ nginx_main_template: user: nginx worker_processes: auto #worker_rlimit_nofile: 1024 - error_level: warn + error_log: + location: /var/log/nginx/error.log + level: warn worker_connections: 1024 http_enable: true http_settings: + access_log_format: + - name: main + format: |- + '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"' + access_log_location: + - name: main + location: /var/log/nginx/access.log keepalive_timeout: 65 cache: false rate_limit: false @@ -368,6 +379,12 @@ nginx_http_template: server_name: localhost include_files: [] error_page: /usr/share/nginx/html + access_log: + - name: main + location: /var/log/nginx/access.log + error_log: + location: /var/log/nginx/error.log + level: warn root: /usr/share/nginx/html https_redirect: false autoindex: false @@ -472,9 +489,9 @@ nginx_http_template: #rewrite: /foo(.*) /$1 break #proxy_pass_request_body: off #allows: - # - 192.168.1.0/24 + # - 192.168.1.0/24 #denies: - # - all + # - all proxy_set_header: header_host: name: Host @@ -566,9 +583,6 @@ nginx_http_template: location: / code: 301 value: http://$host$request_uri - return404: - location: /setup - code: 404 # Enable NGINX status data. # Will enable 'stub_status' in NGINX Open Source and 'status' in NGINX Plus. diff --git a/defaults/main.yml b/defaults/main.yml index 9ebaea5..dc92873 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -147,10 +147,21 @@ nginx_main_template: user: nginx worker_processes: auto #worker_rlimit_nofile: 1024 - error_level: warn + error_log: + location: /var/log/nginx/error.log + level: warn worker_connections: 1024 http_enable: true http_settings: + access_log_format: + - name: main + format: |- + '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"' + access_log_location: + - name: main + location: /var/log/nginx/access.log keepalive_timeout: 65 cache: false rate_limit: false @@ -179,6 +190,12 @@ nginx_http_template: server_name: localhost include_files: [] error_page: /usr/share/nginx/html + access_log: + - name: main + location: /var/log/nginx/access.log + error_log: + location: /var/log/nginx/error.log + level: warn root: /usr/share/nginx/html https_redirect: false autoindex: false diff --git a/molecule/template_module/playbook.yml b/molecule/template_module/playbook.yml index fc6380b..347fa04 100644 --- a/molecule/template_module/playbook.yml +++ b/molecule/template_module/playbook.yml @@ -13,10 +13,21 @@ conf_file_location: /etc/nginx/ user: nginx worker_processes: auto - error_level: warn + error_log: + location: /var/log/nginx/error.log + level: warn worker_connections: 1024 http_enable: true http_settings: + access_log_format: + - name: main + format: | + '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"' + access_log_location: + - name: main + location: /var/log/nginx/access.log keepalive_timeout: 65 cache: false rate_limit: false diff --git a/templates/http/default.conf.j2 b/templates/http/default.conf.j2 index 3df11f5..bff4abf 100644 --- a/templates/http/default.conf.j2 +++ b/templates/http/default.conf.j2 @@ -380,4 +380,14 @@ server { root {{ item.value.error_page }}; } {% endif %} + +{% if item.value.access_log is defined %} +{% for access_log in item.value.access_log %} + access_log {{ access_log.location }} {{ access_log.name }}; +{% endfor %} +{% endif %} +{% if item.value.error_log is defined %} + error_log {{ item.value.error_log.location }} {{ item.value.error_log.level }}; +{% endif %} + } diff --git a/templates/nginx.conf.j2 b/templates/nginx.conf.j2 index 82a6216..3c41901 100644 --- a/templates/nginx.conf.j2 +++ b/templates/nginx.conf.j2 @@ -38,7 +38,7 @@ worker_processes {{ nginx_main_template.worker_processes }}; worker_rlimit_nofile {{ nginx_main_template.worker_rlimit_nofile }}; {% endif %} -error_log /var/log/nginx/error.log {{ nginx_main_template.error_level }}; +error_log {{ nginx_main_template.error_log.location }} {{ nginx_main_template.error_log.level }}; pid /var/run/nginx.pid; @@ -51,11 +51,13 @@ http { include /etc/nginx/mime.types; default_type application/octet-stream; - log_format main '$remote_addr - $remote_user [$time_local] "$request" ' - '$status $body_bytes_sent "$http_referer" ' - '"$http_user_agent" "$http_x_forwarded_for"'; +{% for access_log in nginx_main_template.http_settings.access_log_format %} + log_format {{ access_log.name }} {{ access_log.format }}; +{% endfor %} - access_log /var/log/nginx/access.log main; +{% for access_log in nginx_main_template.http_settings.access_log_location %} + access_log {{ access_log.location }} {{ access_log.name }}; +{% endfor %} sendfile on; #tcp_nopush on;