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 +}