From c94717e020fe4ddd1ce964efca07737ac743eb9f Mon Sep 17 00:00:00 2001 From: "Stefan Hornburg (Racke)" Date: Sat, 9 Jan 2021 15:24:49 +0100 Subject: [PATCH] Add option "nginx_extra_log_formats" to setup multiple log formats in nginx.conf. --- README.md | 9 +++++++++ defaults/main.yml | 2 ++ templates/nginx.conf.j2 | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/README.md b/README.md index 1c00cab..007e1c4 100644 --- a/README.md +++ b/README.md @@ -137,6 +137,15 @@ See the template in `templates/nginx.conf.j2` for more details on the placement. Configures Nginx's [`log_format`](http://nginx.org/en/docs/http/ngx_http_log_module.html#log_format). options. + nginx_extra_log_formats: + - name: gzip + format: |- + '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for" "$gzip_ratio"' + +Additional log formats added to `nginx.conf` below the standard one. + nginx_default_release: "" (For Debian/Ubuntu only) Allows you to set a different repository for the installation of Nginx. As an example, if you are running Debian's wheezy release, and want to get a newer version of Nginx, you can install the `wheezy-backports` repository and set that value here, and Ansible will use that as the `-t` option while installing Nginx. diff --git a/defaults/main.yml b/defaults/main.yml index 0509dbe..788ea90 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -88,3 +88,5 @@ nginx_log_format: |- '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"' + +nginx_extra_log_formats: [] diff --git a/templates/nginx.conf.j2 b/templates/nginx.conf.j2 index 7cdec60..bad4e82 100644 --- a/templates/nginx.conf.j2 +++ b/templates/nginx.conf.j2 @@ -31,6 +31,10 @@ http { log_format main {{ nginx_log_format|indent(23) }}; +{% for format in nginx_extra_log_formats %} + log_format {{ format.name }} {{ format.format|indent(23) }}; +{% endfor %} + access_log {{ nginx_access_log }}; sendfile {{ nginx_sendfile }};