Home / Configs / Servers / logrotate config

logrotate config example: rotate and compress log files

Keep log files from filling your disk: rotate, compress and delete old logs on a schedule.

For Linux with logrotate (Ubuntu, Debian, Fedora, CentOS). Not for macOS or Windows.

logrotate renames old log files, compresses them and deletes the oldest, so logs never fill your disk. Enter the path of your logs and how many copies to keep, then save the result in /etc/logrotate.d.

Create your config file

Type your own values. The file below updates as you type, and nothing you type leaves your browser.

The file name in /etc/logrotate.d

/etc/logrotate.d/myapp
/var/log/myapp/*.log {
    daily
    rotate 14
    compress
    missingok
    notifempty
    create 0640 www-data adm
}

How this setup works

Diagram: Log grows, then logrotate runs, then Old logs kept
Log grows (your app writes it) → logrotate runs (once a day) → Old logs kept (compressed, oldest deleted)

Step-by-step setup

  1. Save the config as /etc/logrotate.d/myapp: sudo nano /etc/logrotate.d/myapp.
  2. Do a dry run that changes nothing: sudo logrotate -d /etc/logrotate.d/myapp.
  3. Force one rotation to see it work: sudo logrotate -f /etc/logrotate.d/myapp.
  4. Look in the log folder. Old logs appear as .1 and .2.gz.
  5. Logrotate then runs by itself, normally once a day.

What the important lines mean

Common errors and how to fix them

error: skipping … because parent directory has insecure permissions
The log folder is writable by someone other than root. Add a line like su root adm inside the braces, using the folder’s owner and group, or fix the folder permissions.
Logs are not rotated
Logrotate checks once a day. Force a run with -f to test, and read /var/lib/logrotate/status.
The app keeps writing to the old file
The app holds the file open. Add a command after rotating that makes it reopen its log, or use copytruncate.
error: unknown option
A typo, or a directive your version does not have. The dry run (-d) shows the line.

Frequently asked questions

Where do logrotate configs go?
In /etc/logrotate.d/, one file per app. The main file /etc/logrotate.conf includes that folder.
How do I test a logrotate config?
Run sudo logrotate -d with the file name for a dry run, and -f to force a rotation.
What does copytruncate do?
It copies the log and empties the original, for apps that cannot reopen their log. A few lines can be lost in between.

Written for: logrotate 3.21, Ubuntu 24.04 · Updated 2026-10-03

More server configs

See all 41 config generators