r/nginx: Make logging to files optional

If _nginx_ is configured to send error/access log messages to syslog, it
may not make sense to _also_ send messages to log files as well.  The
`nginx_error_log_file` and `nginx_access_log_file` variables are now
available to control whether/where to send log messages.  Setting either
of these to a falsy value will disable logging to a file.  A non-empty
string value is interpreted as the path to a log file.  By default, the
existing behavior of logging to `/var/log/nginx/error.log` and
`/var/log/nginx/access.log` is preserved.
frigate-exporter
Dustin 2024-10-14 11:38:05 -05:00
parent a0c5ffc869
commit 845911dcbd
2 changed files with 8 additions and 2 deletions

View File

@ -4,5 +4,7 @@ nginx_ssl_session_cache: shared:SSL:1m
nginx_ssl_session_timeout: 10m nginx_ssl_session_timeout: 10m
nginx_ssl_ciphers: '{{ nginx_default_ssl_ciphers }}' nginx_ssl_ciphers: '{{ nginx_default_ssl_ciphers }}'
nginx_log_syslog: true nginx_log_syslog: true
nginx_error_log_file: /var/log/nginx/error.log
nginx_access_log_file: /var/log/nginx/access.log
nginx_redirect_http_https: false nginx_redirect_http_https: false
nginx_keep_num_logs: 10 nginx_keep_num_logs: 10

View File

@ -4,7 +4,9 @@
user {{ nginx_user }}; user {{ nginx_user }};
worker_processes auto; worker_processes auto;
error_log /var/log/nginx/error.log; {% if nginx_error_log_file %}
error_log {{ nginx_error_log_file }};
{% endif %}
{% if nginx_log_syslog|bool %} {% if nginx_log_syslog|bool %}
error_log syslog:server=unix:/dev/log,facility=daemon,nohostname; error_log syslog:server=unix:/dev/log,facility=daemon,nohostname;
{% endif %} {% endif %}
@ -22,7 +24,9 @@ http {
'$status $body_bytes_sent "$http_referer" ' '$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'; '"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main; {% if nginx_access_log_file %}
access_log {{ nginx_access_log_file }} main;
{% endif %}
{% if nginx_log_syslog|bool %} {% if nginx_log_syslog|bool %}
access_log syslog:server=unix:/dev/log,facility=daemon,nohostname main; access_log syslog:server=unix:/dev/log,facility=daemon,nohostname main;
{% endif %} {% endif %}