From 9edba6e8267f8f513978f6608e9fb503339b9424 Mon Sep 17 00:00:00 2001 From: vincent Date: Wed, 3 Mar 2021 09:31:54 +0100 Subject: [PATCH] add logrotate to nginx --- defaults/main.yml | 5 ++++- tasks/main.yml | 5 +++++ templates/logrotate/nginx.j2 | 11 +++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 templates/logrotate/nginx.j2 diff --git a/defaults/main.yml b/defaults/main.yml index d5191c8..1b63f90 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -86,4 +86,7 @@ nginx_log_format: |- '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"' -nginx_realIP_Proxy: None \ No newline at end of file +nginx_realIP_Proxy: None +nginx_logrotate_number: 4 +## weekly,dailly.. +nginx_logrotate_period: "weekly" diff --git a/tasks/main.yml b/tasks/main.yml index 74eb575..5dae387 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -53,6 +53,11 @@ - reload nginx when: nginx_realIP_Proxy is defined +- name: Apply logrotate file + template: + dest: /etc/logrotate.d/nginx + src: logrotate/nginx.j2 + - name: Ensure nginx is started and enabled to start at boot. service: name: nginx diff --git a/templates/logrotate/nginx.j2 b/templates/logrotate/nginx.j2 new file mode 100644 index 0000000..9713f01 --- /dev/null +++ b/templates/logrotate/nginx.j2 @@ -0,0 +1,11 @@ + /var/log/nginx/*log { + create 0644 + {{ nginx_logrotate_period }} + rotate {{nginx_logrotate_number}} + missingok + notifempty + sharedscripts + postrotate + /bin/kill -USR1 `cat /run/nginx.pid 2>/dev/null` 2>/dev/null || true + endscript +}