Browse Source

add logrotate to nginx

master
vincent 9 months ago
parent
commit
9edba6e826
  1. 5
      defaults/main.yml
  2. 5
      tasks/main.yml
  3. 11
      templates/logrotate/nginx.j2

5
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
nginx_realIP_Proxy: None
nginx_logrotate_number: 4
## weekly,dailly..
nginx_logrotate_period: "weekly"

5
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

11
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
}
Loading…
Cancel
Save