Learn about Centmin Mod LEMP Stack today
Register Now

nginx access log retention

Discussion in 'System Administration' started by Rake-GH, Jan 21, 2021.

  1. Rake-GH

    Rake-GH Active Member

    154
    80
    28
    Jul 29, 2019
    USA
    Ratings:
    +118
    Local Time:
    8:29 AM
    default
    default
    in /home/nginx/domains/domainname/log it only lists 30 days of logs

    I want to keep logs permanently, what do I need to change?

    Thank you in advance.
     
  2. eva2000

    eva2000 Administrator Staff Member

    46,238
    10,510
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +16,293
    Local Time:
    11:29 PM
    Nginx 1.19.x
    MariaDB 5.5/10.x

    Centmin Mod Log Rotation



    Centmin Mod should be auto log rotating your access and error logs via logrotate.

    You can modify how long you retain your nginx logs before the logs are rotated by logrtate at /etc/logrotate.d/nginx. Below examples rotate logs daily or whenever they hit 500MB in size, keeping the last 10 logs (rotate 10)

    Centmin Mod 123.09beta01's nginx log rotate would have the following log rotate config file /etc/logrotate.d/nginx contents if you server has more than 1153433 bytes of memory and more than 10485760 bytes of disk free space in /var partition
    Code (Text):
    /var/log/nginx/*.log /usr/local/nginx/logs/*.log /home/nginx/domains/*/log/*.log {
            daily
            dateext
            missingok
            rotate 10
            compress
            delaycompress
            notifempty
            postrotate
            /bin/kill -SIGUSR1 $(cat /usr/local/nginx/logs/nginx.pid 2>/dev/null) 2>/dev/null || true
            endscript          
    }
    

    If you server has less than 1153433 bytes of memory and less than 10485760 bytes of disk free space in /var partition
    Code (Text):
    /var/log/nginx/*.log /usr/local/nginx/logs/*.log /home/nginx/domains/*/log/*.log {
            daily
            dateext
            missingok
            rotate 10
            maxsize 500M
            compress
            delaycompress
            notifempty
            postrotate
            /bin/kill -SIGUSR1 $(cat /usr/local/nginx/logs/nginx.pid 2>/dev/null) 2>/dev/null || true
            endscript          
    }
    

    You can do a debug run of logrotate to see what happens when logrortate is meant to rotate your logs using SSH command
    Code (Text):
    logrotate -d /etc/logrotate.d/nginx
    
     
  3. Rake-GH

    Rake-GH Active Member

    154
    80
    28
    Jul 29, 2019
    USA
    Ratings:
    +118
    Local Time:
    8:29 AM
    default
    default
    Perfect thank you