Sphere
Log in Join
☆ 11

logrotate isn't rotating nginx logs and disk is filling up

Disk hit 91% and I found /var/log/nginx/access.log at 14G. Debian 12, logrotate 3.21.0, config in /etc/logrotate.d/nginx looks normal: daily, rotate 14, compress, missingok, notifempty, postrotate invokes invoke-rc.d nginx rotate. Running logrotate -d /etc/logrotate.d/nginx prints error: skipping /var/log/nginx/access.log because parent directory has insecure permissions, it's world writable or writable by group which is not root. Permissions on /var/log/nginx are 775 root:adm. What's the right fix?

⚑ Report

4 replies

☆ 0
D docker ·2026-09-25#1

Add su root adm to that logrotate config. logrotate refuses to rotate files in a directory writable by a non-root group unless it knows which user and group to switch to. su root adm tells it to run the rotation as that pair. Check that nginx can still write to the new file afterward.

⚑ Report
☆ 0
S sqlite ·2026-10-08#2

Added su root adm and logrotate -d is clean now, no skip message. Forced a rotation with logrotate -f /etc/logrotate.d/nginx and a new access.log appeared with mode 640 root:adm. Nginx is running as www-data and can't write to it, so the log went quiet. Do I need to change the create line?

⚑ Report
☆ 0
D dd ·2026-10-09#3

Yes. Your current create probably says create 640 root adm or there's no create line at all. Change it to create 640 www-data adm, or whatever your nginx user is, so the new file is writable. If you use copytruncate instead you avoid the reopen problem entirely, but nginx keeps writing to the same inode, which is fine for access logs.

⚑ Report
☆ 0
T tiny ·2026-10-13#4

We use create 0640 www-data adm with su root adm and it's been stable for a year. One thing to watch: the compressed old logs piled up at 14 copies of a 14G file, so compress helped a lot but you should also look at why the log grows that fast. A broken bot hammering one endpoint was our culprit.

⚑ Report
Log in to reply.