'Nginx custom access log does not rotate
I have configured a custom log in html section of nginx.conf:
log_format jsonlog escape=json '{ "time": "$time_iso8601", '
'"remote_addr": "$remote_addr", '
'"remote_user": "$remote_user", '
'"ssl_protocol_cipher": "$ssl_protocol/$ssl_cipher", '
'"body_bytes_sent": "$body_bytes_sent", '
'"request_time": "$request_time", '
'"status": "$status", '
'"request": "$request", '
'"request_method": "$request_method", '
'"http_referrer": "$http_referer", '
'"http_x_forwarded_for": "$http_x_forwarded_for", '
'"http_cf_ray": "$http_cf_ray", '
'"host": "$host", '
'"server_name": "$server_name", '
'"upstream_address": "$upstream_addr", '
'"upstream_status": "$upstream_status", '
'"upstream_response_time": "$upstream_response_time", '
'"upstream_response_length": "$upstream_response_length", '
'"upstream_cache_status": "$upstream_cache_status", '
'"http_user_agent": "$http_user_agent" }';
access_log /var/log/nginx/json.access.log jsonlog;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
While access.log and error.log rotate, json.access.log doesn't.
This is my nginx logrotate configuration (/etc/logrotate.d/nginx):
/var/log/nginx/*.log {
daily
missingok
rotate 14
compress
delaycompress
notifempty
create 0644 www-data adm
sharedscripts
prerotate
if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
run-parts /etc/logrotate.d/httpd-prerotate; \
fi \
endscript
postrotate
invoke-rc.d nginx rotate >/dev/null 2>&1
endscript
}
I think that this logrotate configuration is not applied to my custom log because the log file is created with root group instead of adm (as specified in create 0644 www-data adm):
-rw-r--r-- 1 www-data adm 28316313 30 mar 09.10 access.log
-rw-r--r-- 1 www-data adm 79362122 30 mar 00.00 access.log.1
...
-rw-r--r-- 1 www-data root 141300465 30 mar 09.10 json.access.log
What did I do wrong?
UPDATE
I've tried to force rotation with sudo /usr/sbin/logrotate -f /etc/logrotate.d/nginx and it has worked fine, and also the group is now correct:
-rw-r--r-- 1 www-data adm 10237 30 mar 14.59 json.access.log
-rw-r--r-- 1 www-data adm 90410 30 mar 14.59 json.access.log.1
-rw-r--r-- 1 www-data root 5767548 30 mar 14.58 json.access.log.2.gz
Let's see if tomorrow it will be rotated automatically...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
