add logrotate to nginx

This commit is contained in:
vincent 2021-03-03 09:31:54 +01:00
parent 5ce506eb3d
commit 9edba6e826
3 changed files with 20 additions and 1 deletions

View File

@ -86,4 +86,7 @@ nginx_log_format: |-
'$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"'
nginx_realIP_Proxy: None nginx_realIP_Proxy: None
nginx_logrotate_number: 4
## weekly,dailly..
nginx_logrotate_period: "weekly"

View File

@ -53,6 +53,11 @@
- reload nginx - reload nginx
when: nginx_realIP_Proxy is defined 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. - name: Ensure nginx is started and enabled to start at boot.
service: service:
name: nginx name: nginx

View File

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