Add templating options to logs (#169)

Resolves #152
This commit is contained in:
Alessandro Fael Garcia 2019-10-02 19:29:59 +02:00 committed by GitHub
parent 3b0e39f870
commit c6c133674e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 67 additions and 13 deletions

View File

@ -336,10 +336,21 @@ nginx_main_template:
user: nginx user: nginx
worker_processes: auto worker_processes: auto
#worker_rlimit_nofile: 1024 #worker_rlimit_nofile: 1024
error_level: warn error_log:
location: /var/log/nginx/error.log
level: warn
worker_connections: 1024 worker_connections: 1024
http_enable: true http_enable: true
http_settings: 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 keepalive_timeout: 65
cache: false cache: false
rate_limit: false rate_limit: false
@ -368,6 +379,12 @@ nginx_http_template:
server_name: localhost server_name: localhost
include_files: [] include_files: []
error_page: /usr/share/nginx/html 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 root: /usr/share/nginx/html
https_redirect: false https_redirect: false
autoindex: false autoindex: false
@ -472,9 +489,9 @@ nginx_http_template:
#rewrite: /foo(.*) /$1 break #rewrite: /foo(.*) /$1 break
#proxy_pass_request_body: off #proxy_pass_request_body: off
#allows: #allows:
# - 192.168.1.0/24 # - 192.168.1.0/24
#denies: #denies:
# - all # - all
proxy_set_header: proxy_set_header:
header_host: header_host:
name: Host name: Host
@ -566,9 +583,6 @@ nginx_http_template:
location: / location: /
code: 301 code: 301
value: http://$host$request_uri value: http://$host$request_uri
return404:
location: /setup
code: 404
# Enable NGINX status data. # Enable NGINX status data.
# Will enable 'stub_status' in NGINX Open Source and 'status' in NGINX Plus. # Will enable 'stub_status' in NGINX Open Source and 'status' in NGINX Plus.

View File

@ -147,10 +147,21 @@ nginx_main_template:
user: nginx user: nginx
worker_processes: auto worker_processes: auto
#worker_rlimit_nofile: 1024 #worker_rlimit_nofile: 1024
error_level: warn error_log:
location: /var/log/nginx/error.log
level: warn
worker_connections: 1024 worker_connections: 1024
http_enable: true http_enable: true
http_settings: 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 keepalive_timeout: 65
cache: false cache: false
rate_limit: false rate_limit: false
@ -179,6 +190,12 @@ nginx_http_template:
server_name: localhost server_name: localhost
include_files: [] include_files: []
error_page: /usr/share/nginx/html 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 root: /usr/share/nginx/html
https_redirect: false https_redirect: false
autoindex: false autoindex: false

View File

@ -13,10 +13,21 @@
conf_file_location: /etc/nginx/ conf_file_location: /etc/nginx/
user: nginx user: nginx
worker_processes: auto worker_processes: auto
error_level: warn error_log:
location: /var/log/nginx/error.log
level: warn
worker_connections: 1024 worker_connections: 1024
http_enable: true http_enable: true
http_settings: 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 keepalive_timeout: 65
cache: false cache: false
rate_limit: false rate_limit: false

View File

@ -380,4 +380,14 @@ server {
root {{ item.value.error_page }}; root {{ item.value.error_page }};
} }
{% endif %} {% 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 %}
} }

View File

@ -38,7 +38,7 @@ worker_processes {{ nginx_main_template.worker_processes }};
worker_rlimit_nofile {{ nginx_main_template.worker_rlimit_nofile }}; worker_rlimit_nofile {{ nginx_main_template.worker_rlimit_nofile }};
{% endif %} {% 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; pid /var/run/nginx.pid;
@ -51,11 +51,13 @@ http {
include /etc/nginx/mime.types; include /etc/nginx/mime.types;
default_type application/octet-stream; default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' {% for access_log in nginx_main_template.http_settings.access_log_format %}
'$status $body_bytes_sent "$http_referer" ' log_format {{ access_log.name }} {{ access_log.format }};
'"$http_user_agent" "$http_x_forwarded_for"'; {% 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; sendfile on;
#tcp_nopush on; #tcp_nopush on;